Package org.geotools.coverage.grid.io

Examples of org.geotools.coverage.grid.io.AbstractGridCoverage2DReader


                            pm.beginTask("Collecting stats...", IProgressMonitor.UNKNOWN);
                            StringBuilder regionString = new StringBuilder();
                            GridCoverage2D geodata = null;
                            if (object instanceof AbstractRasterGeoResource) {
                                AbstractRasterGeoResource rGeo = (AbstractRasterGeoResource) object;
                                AbstractGridCoverage2DReader gridCoverage2DReader = rGeo.resolve(
                                        AbstractGridCoverage2DReader.class, pm);
                                geodata = ((GridCoverage2D) gridCoverage2DReader.read(null));
                                geodata = geodata.view(ViewType.GEOPHYSICS);

                                Envelope envelope = geodata.getEnvelope();
                                DirectPosition lowerCorner = envelope.getLowerCorner();
                                double[] westSouth = lowerCorner.getCoordinate();
                                DirectPosition upperCorner = envelope.getUpperCorner();
                                double[] eastNorth = upperCorner.getCoordinate();
                                GridGeometry2D gridGeometry = geodata.getGridGeometry();
                                GridEnvelope2D gridRange = gridGeometry.getGridRange2D();
                                int rows = gridRange.height;
                                int cols = gridRange.width;

                                AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS();
                                double we_res = XAffineTransform.getScaleX0(gridToCRS);
                                double ns_res = XAffineTransform.getScaleY0(gridToCRS);
                                double north = eastNorth[1];
                                double south = westSouth[1];
                                double east = eastNorth[0];
                                double west = westSouth[0];
                                regionString.append("region:\nwest=");
                                regionString.append(west);
                                regionString.append("\neast=");
                                regionString.append(east);
                                regionString.append("\nsouth=");
                                regionString.append(south);
                                regionString.append("\nnorth=");
                                regionString.append(north);
                                regionString.append("\nwe_res=");
                                regionString.append(we_res);
                                regionString.append("\nns_res=");
                                regionString.append(ns_res);
                                regionString.append("\nrows=");
                                regionString.append(rows);
                                regionString.append("\ncols=");
                                regionString.append(cols);

                            } else if (object instanceof JGrassMapGeoResource) {
                                JGrassMapGeoResource mr = (JGrassMapGeoResource) object;
                                File mapFile = mr.getMapFile();
                                JGrassMapEnvironment mapEnvironment = new JGrassMapEnvironment(mapFile);
                                JGrassRegion jGrassRegion = mapEnvironment.getActiveRegion();

                                int cols = jGrassRegion.getCols();
                                int rows = jGrassRegion.getRows();
                                double north = jGrassRegion.getNorth();
                                double south = jGrassRegion.getSouth();
                                double east = jGrassRegion.getEast();
                                double west = jGrassRegion.getWest();
                                double we_res = jGrassRegion.getWEResolution();
                                double ns_res = jGrassRegion.getNSResolution();
                                regionString.append("region:\nwest=");
                                regionString.append(west);
                                regionString.append("\neast=");
                                regionString.append(east);
                                regionString.append("\nsouth=");
                                regionString.append(south);
                                regionString.append("\nnorth=");
                                regionString.append(north);
                                regionString.append("\nwe_res=");
                                regionString.append(we_res);
                                regionString.append("\nns_res=");
                                regionString.append(ns_res);
                                regionString.append("\nrows=");
                                regionString.append(rows);
                                regionString.append("\ncols=");
                                regionString.append(cols);

                                GeneralParameterValue[] readParams = createGridGeometryGeneralParameter(cols, rows, north, south,
                                        east, west, mapEnvironment.getCoordinateReferenceSystem());
                                AbstractGridFormat format = (AbstractGridFormat) new GrassCoverageFormatFactory().createFormat();
                                AbstractGridCoverage2DReader reader = format.getReader(mapEnvironment.getCELL());
                                geodata = ((GridCoverage2D) reader.read(readParams));
                                geodata = geodata.view(ViewType.GEOPHYSICS);
                            } else {
                                MessageDialog.openInformation(shell, "WARNING", "Unable to read format");
                                return;
                            }
View Full Code Here


        // try to go for the reader first
        boolean isOnGrid = false;
        boolean hasProblem = false;
        Point2D p = null;
        if (geoResource.canResolve(AbstractGridCoverage2DReader.class)) {
            AbstractGridCoverage2DReader reader = geoResource.resolve(AbstractGridCoverage2DReader.class, monitor);
            GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope();
            CoordinateReferenceSystem targetCrs = reader.getCrs();

            if (targetCrs != null) {
                evaluateCoord = transform(sourceCRS, targetCrs, envelopeCenterOrig);
            } else {
                evaluateCoord = envelopeCenterOrig;
                targetCrs = sourceCRS;
            }
            p = new Point2D.Double(evaluateCoord.x, evaluateCoord.y);
            if (originalEnvelope.contains(new DirectPosition2D(p))) {
                double delta = 0.0000001;
                GeneralParameterValue[] parameterValues = createGridGeometryGeneralParameter(1, 1, evaluateCoord.y + delta,
                        evaluateCoord.y - delta, evaluateCoord.x + delta, evaluateCoord.x - delta, targetCrs);
                coverage = reader.read(parameterValues);
                /*
                 * the following is done since the reader might read a singlwe pixel
                 * region and the gridcoordinate would be 0, 0 in that case. Later
                 * we want to supply the gridcoordinate of the position in the whole
                 * coverage.
                 */
                gridGeometry = new GridGeometry2D(reader.getOriginalGridRange(), reader.getOriginalEnvelope());
                isOnGrid = true;
            }
        }
        // else try with coverage
        else if (geoResource.canResolve(GridCoverage.class)) {
View Full Code Here

                                            jGrassRegion.getCols(), jGrassRegion.getRows(), jGrassRegion.getNorth(),
                                            jGrassRegion.getSouth(), jGrassRegion.getEast(), jGrassRegion.getWest(),
                                            oldMapEnvironment.getCoordinateReferenceSystem());
                                    AbstractGridFormat format = (AbstractGridFormat) new GrassCoverageFormatFactory()
                                            .createFormat();
                                    AbstractGridCoverage2DReader reader = format.getReader(oldMapEnvironment.getCELL());
                                    GridCoverage2D geodata = ((GridCoverage2D) reader.read(readParams));
                                    geodata = geodata.view(ViewType.GEOPHYSICS);

                                    File mapsetFile = oldMapEnvironment.getMAPSET();
                                    JGrassMapEnvironment newMapEnvironment = new JGrassMapEnvironment(mapsetFile, newMapName);
                                    format = new GrassCoverageFormatFactory().createFormat();
View Full Code Here

     * it loads a very small coverage for getting info from but not using as a real datasource
     * @return
     * @throws IOException
     */
    protected GridCoverage loadCoverage() throws IOException {
        AbstractGridCoverage2DReader reader = this.service(new NullProgressMonitor()).getReader(null);
        ParameterGroup pvg = getReadParameters();
        List<GeneralParameterValue> list = pvg.values();
        GeneralParameterValue[] values = list.toArray(new GeneralParameterValue[0]);
        GridCoverage gridCoverage = reader.read(values);
        return gridCoverage;
    }
View Full Code Here

            }
            if (adaptee.isAssignableFrom(GridCoverageLoader.class)) {
                return adaptee.cast(new GridCoverageLoader(this));
            }
            if (adaptee.isAssignableFrom(AbstractGridCoverage2DReader.class)) {
                AbstractGridCoverage2DReader reader = service(monitor).getReader(monitor);
                return adaptee.cast(reader);
            }
            if (adaptee.isAssignableFrom(GridCoverage.class)) {
                return adaptee.cast(findResource());
            }
View Full Code Here

 
  public <T> T adapt(IResolve resolve, Class<T> adapter,
      IProgressMonitor monitor) throws IOException {
   
    if( adapter.isAssignableFrom(ImageMosaicReader.class)){
        AbstractGridCoverage2DReader reader = toGridCoverage2DReader( resolve, monitor);
        return adapter.cast( reader);
    }   
    return null;
  }
View Full Code Here

   
    public GridCoverage load( GeneralGridGeometry geom, IProgressMonitor monitor ) throws IOException {

        ParameterValueGroup group = resource.resolve(ParameterValueGroup.class, monitor);

        AbstractGridCoverage2DReader reader = resource.resolve( AbstractGridCoverage2DReader.class, monitor);
        if (group == null){
            group = reader.getFormat().getReadParameters();
        }
        else {
            // temporary fix for imageio
            try {
                ParameterValue< ? > tempParam = group
                        .parameter(AbstractGridFormat.USE_JAI_IMAGEREAD.getName().toString());
                if (tempParam != null)
                    tempParam.setValue(false);
            } catch (ParameterNotFoundException e) {
                // do nothing
            }
        }
        ParameterValue< ? > param = group.parameter(AbstractGridFormat.READ_GRIDGEOMETRY2D
                .getName().toString());
        param.setValue(geom);

        GridCoverage2D coverage = (GridCoverage2D) reader.read(group.values().toArray(
                new ParameterValue[0]));
       
        return coverage;
    }
View Full Code Here

        }
       
        final int numberOfexpectedInfoFields = 2;
        int numberOfAvailableInfoFields = 0;

        AbstractGridCoverage2DReader reader = null;

        try {
            IProgressMonitor monitor = new NullProgressMonitor();
            monitor.setTaskName("Checking availability of metadata for " + service.getTitle());
           
            reader = service.getReader(monitor);

            CoordinateReferenceSystem CRS = reader.getCrs();

            if (!(CRS instanceof DefaultEngineeringCRS))
                numberOfAvailableInfoFields++;
           
            GeneralEnvelope env = reader.getOriginalEnvelope();
           
            if (!(env.isEmpty() || env.isNull() || env.isInfinite()))
                numberOfAvailableInfoFields++;

            completeness = (double) numberOfexpectedInfoFields
                    / (double) numberOfAvailableInfoFields;

        } finally {
            reader.dispose();//clean up render.
        }
       
        return completeness;
    }
View Full Code Here

    @Override
    public synchronized ReferencedEnvelope getBounds() {
        if (this.bounds == null) {
            try {
                AbstractGridCoverage2DReader source = this.resource.service(new NullProgressMonitor()).getReader(null);
                if (source == null) {
                    return null;
                }

                GeneralEnvelope ptBounds = source.getOriginalEnvelope();
                Envelope env = new Envelope(ptBounds.getMinimum(0), ptBounds.getMaximum(0),
                        ptBounds.getMinimum(1), ptBounds.getMaximum(1));

                CoordinateReferenceSystem geomcrs = source.getCrs();
                if (geomcrs == null) {
                    geomcrs = DefaultEngineeringCRS.GENERIC_2D;
                }

                this.bounds = new ReferencedEnvelope(env, geomcrs);
View Full Code Here

            Rectangle screenSize = new Rectangle( upperLeft );
            screenSize.add( bottomRight );
          IMapDisplay mapDisplay = currentContext.getMapDisplay();
           
          
             AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) geoResource.resolve( AbstractGridCoverage2DReader.class, monitor);
             if( reader == null ){
                 return; // unable to connect!
             }
             CoordinateReferenceSystem destinationCRS = currentContext.getCRS();
             ReferencedEnvelope bounds = (ReferencedEnvelope) currentContext.getImageBounds();
             bounds=bounds.transform(destinationCRS, true);
            
             ParameterValueGroup group = geoResource.resolve( ParameterValueGroup.class, monitor);
             if(group==null){
                 group=reader.getFormat().getReadParameters();
             }
             else{
                 // temporary fix for image-io (JG: what is the nature of this fix?)
                 try{
                     ParameterValue<?> jaiImageReaderParam = group.parameter(AbstractGridFormat.USE_JAI_IMAGEREAD.getName().toString());
                     if(jaiImageReaderParam!=null){
                         jaiImageReaderParam.setValue(false);
                     }
                 }catch (ParameterNotFoundException e) {
                     // do nothing
                 }
             }
             ParameterValue<?> readGridGeometry2DParam = group.parameter(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString());

//            GridEnvelope range = new GridEnvelope2D(0, 0, mapDisplay.getWidth(), mapDisplay.getHeight());
//            MathTransform displayToLayer = currentContext.worldToScreenMathTransform().inverse();
//            ReferencingFactoryFinder.getMathTransformFactory(null).createConcatenatedTransform(displayToLayer,
//                    currentContext.getLayer().mapToLayerTransform());
//            GridGeometry2D geom = new GridGeometry2D(range, displayToLayer, destinationCRS);
//            readGridGeometry2DParam.setValue(geom);

            GridEnvelope2D gridEnvelope = new GridEnvelope2D(0, 0, mapDisplay.getWidth(), mapDisplay.getHeight());
            org.opengis.geometry.Envelope env;
            double west= bounds.getMinX();
            double east= bounds.getMaxX();
            double south= bounds.getMinY();
            double north= bounds.getMaxY();
            if (destinationCRS != null) {
                env = new ReferencedEnvelope(west, east, south, north, destinationCRS);
            } else {
                DirectPosition2D minDp = new DirectPosition2D(west, south);
                DirectPosition2D maxDp = new DirectPosition2D(east, north);
                env = new Envelope2D(minDp, maxDp);
            }
            readGridGeometry2DParam.setValue(new GridGeometry2D(gridEnvelope, env));

             currentContext.setStatus(ILayer.WORKING);
             setState( STARTING );
            
             ParameterValue[] parameterValues = group.values().toArray(new ParameterValue[0]);
            GridCoverage2D coverage = (GridCoverage2D) reader.read(parameterValues);
             if(coverage!=null){             
              //setting rendering hints
                 //
              RenderingHints hints = new RenderingHints(new HashMap<RenderingHints.Key,Object>());
              hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED));
View Full Code Here

TOP

Related Classes of org.geotools.coverage.grid.io.AbstractGridCoverage2DReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.