Examples of GridGeometry2D


Examples of org.geotools.coverage.grid.GridGeometry2D

        // apply the bounds, taking into account the reprojection policy if need be
        if (rinfo.getProjectionPolicy() == ProjectionPolicy.REPROJECT_TO_DECLARED && bounds != null) {
            try {
                bounds = bounds.transform(rinfo.getCRS(), true);
                GridGeometry grid = ((CoverageInfo) rinfo).getGrid();
                ((CoverageInfo) rinfo).setGrid(new GridGeometry2D(grid.getGridRange(),grid.getGridToCRS(), rinfo.getCRS()));
            } catch(Exception e) {
                throw (IOException) new IOException("transform error").initCause(e);
            }
        }
       
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

        GeneralEnvelope envelope = reader.getOriginalEnvelope();
        cinfo.setNativeBoundingBox( new ReferencedEnvelope( envelope ) );
        cinfo.setLatLonBoundingBox( new ReferencedEnvelope(CoverageStoreUtils.getWGS84LonLatEnvelope(envelope)) );
       
        GridEnvelope originalRange=reader.getOriginalGridRange();
        cinfo.setGrid(new GridGeometry2D(originalRange,reader.getOriginalGridToWorld(PixelInCell.CELL_CENTER),nativeCRS));

        ///////////////////////////////////////////////////////////////////////
        //
        // Now reading a fake small GridCoverage just to retrieve meta
                // information about bands:
        //
        // - calculating a new envelope which is 1/20 of the original one
        // - reading the GridCoverage subset
        //
        ///////////////////////////////////////////////////////////////////////
        Format format = csinfo.getFormat();
        final GridCoverage2D gc;

       
        final ParameterValueGroup readParams = format.getReadParameters();
        final Map parameters = CoverageUtils.getParametersKVP(readParams);
        final int minX=originalRange.getLow(0);
        final int minY=originalRange.getLow(1);
        final int width=originalRange.getSpan(0);
        final int height=originalRange.getSpan(1);
        final int maxX=minX+(width<=5?width:5);
        final int maxY=minY+(height<=5?height:5);
       
        //we have to be sure that we are working against a valid grid range.
        final GridEnvelope2D testRange= new GridEnvelope2D(minX,minY,maxX,maxY);
       
        //build the corresponding envelope
        final MathTransform gridToWorldCorner =  reader.getOriginalGridToWorld(PixelInCell.CELL_CORNER);
        final GeneralEnvelope testEnvelope =CRS.transform(gridToWorldCorner,new GeneralEnvelope(testRange.getBounds()));
        testEnvelope.setCoordinateReferenceSystem(nativeCRS);
       
        parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
            new GridGeometry2D(testRange, testEnvelope));

        //try to read this coverage
        gc = (GridCoverage2D) reader.read(CoverageUtils.getParameters(readParams, parameters,
                    true));
        if(gc==null){
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

            };
        final GeneralEnvelope subEnvelope = new GeneralEnvelope(minCP, maxCP);
        subEnvelope.setCoordinateReferenceSystem(reader.getCrs());

        parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
            new GridGeometry2D(reader.getOriginalGridRange(), subEnvelope));
        GridCoverage2D gc = (GridCoverage2D) reader.read(CoverageUtils.getParameters(readParams, parameters,
                    true));
       
        // grid geometry
        final GridGeometry geometry = gc.getGridGeometry();
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

      //
      // Reading the coverage
      //
      // /////////////////////////////////////////////////////////
      parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
          new GridGeometry2D(new GeneralGridEnvelope(destinationSize), destinationEnvelopeInSourceCRS));
 
      final GridCoverage coverage = coverageReader.read(CoverageUtils.getParameters(
                  coverageReader.getFormat().getReadParameters(), parameters, true));
 
      if ((coverage == null) || !(coverage instanceof GridCoverage2D)) {
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

        // Let me now scale down to the EXACT needed resolution. This step does
        // not prevent from having loaded an overview of the original image
        // based on the requested scale.
        //
        // ///////////////////////////////////////////////////////////////////
        GridGeometry2D scaledGridGeometry = new GridGeometry2D(newGridRange,
                (destinationEnvelopeInSourceCRS != null) ? destinationEnvelopeInSourceCRS
                                                         : sourceCoverage.getEnvelope());

        /*
         * Operations.DEFAULT.resample( coverage, sourceCRS, scaledGridGeometry,
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

    final GridGeometry2D gg;
    final int width, height;
   
    Tile(TileRequest req) {
        GridEnvelope2D gridEnv = new GridEnvelope2D(0, 0, req.width, req.height);
        this.gg = new GridGeometry2D(gridEnv, (org.opengis.geometry.Envelope)(req.bbox));
        // TODO: check that gg intersects graph area
        LOG.debug("preparing tile for {}", gg.getEnvelope2D());
        // Envelope2D worldEnv = gg.getEnvelope2D();
        this.width = gridEnv.width;
        this.height = gridEnv.height;
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

        if (boundsFromGraph) {
            // autowire graph service or pass in
        }
        gridEnvelope = new GridEnvelope2D(0, 0, cols, rows);
        refEnvelope = new ReferencedEnvelope(left, right, bottom, top, coverageCRS);
        gridGeometry = new GridGeometry2D(gridEnvelope, refEnvelope);
        super.createIndividuals0();
    }
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

            // determine file format and CRS, then load raster
            AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile);
            AbstractGridCoverage2DReader reader = format.getReader(rasterFile);
            GridCoverage2D coverage = reader.read(null);
            this.coverageCRS = coverage.getCoordinateReferenceSystem();
            GridGeometry2D gridGeometry = coverage.getGridGeometry();
            GridEnvelope2D gridEnvelope = gridGeometry.getGridRange2D();
            gridGeometry.getGridToCRS();
            // because we may want to produce an empty raster rather than loading one, alongside the coverage we
            // store the row/col dimensions and the referenced envelope in the original coordinate reference system.
            this.cols  = gridEnvelope.width;
            this.rows = gridEnvelope.height;
            this.createIndividuals0();
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

        CoordinateReferenceSystem targetCRS = (CoordinateReferenceSystem)
                parameters.parameter("CoordinateReferenceSystem").getValue();
        if (targetCRS == null) {
            targetCRS = source.getCoordinateReferenceSystem();
        }
        final GridGeometry2D targetGG = GridGeometry2D.wrap(
                (GridGeometry) parameters.parameter("GridGeometry").getValue());
        final Object bgValueParam = parameters.parameter("BackgroundValues");
        final double [] bgValues;
        if (bgValueParam != null && bgValueParam instanceof Parameter<?>){
            bgValues = ((Parameter<double[]>)bgValueParam).getValue();
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

            if (reducedCRS == sourceCRS) {
                gridToCRS = gridGeometry.getGridToCRS();
            } else {
                gridToCRS = GridGeometry2D.wrap(gridGeometry).getGridToCRS2D();
            }
            gridGeometry = new GridGeometry2D(PixelInCell.CELL_CENTER, gridToCRS, target, null);
        } else {
            /*
             * Different CRS. We need to infer an image size, which may be the same than the
             * original size or something smaller if the envelope is a subarea. We process by
             * transforming the target envelope to the source CRS and compute a new grid geometry
             * with that envelope. The grid range of that grid geometry is the new image size.
             * Note that failure to transform the envelope is non-fatal (we will assume that the
             * target image should have the same size). Then create again a new grid geometry,
             * this time with the target envelope.
             */
            GridEnvelope gridRange;
            try {
                final GeneralEnvelope transformed;
                transformed = CRS.transform(CRS.getCoordinateOperationFactory(true)
                        .createOperation(targetCRS, reducedCRS), target);
                final Envelope reduced;
                final MathTransform gridToCRS;
                if (reducedCRS == sourceCRS) {
                    reduced   = source.getEnvelope();
                    gridToCRS = gridGeometry.getGridToCRS();
                } else {
                    reduced   = CoverageUtilities.getEnvelope2D(source);
                    gridToCRS = GridGeometry2D.wrap(gridGeometry).getGridToCRS2D();
                }
                transformed.intersect(reduced);
                gridGeometry = new GridGeometry2D(PixelInCell.CELL_CENTER, gridToCRS, transformed, null);
            } catch (FactoryException exception) {
                recoverableException("resample", exception);
            } catch (TransformException exception) {
                recoverableException("resample", exception);
                // Will use the grid range from the original geometry,
                // which will result in keeping the same image size.
            }
            gridRange = gridGeometry.getGridRange();
            gridGeometry = new GridGeometry2D(gridRange, target);
        }
        return gridGeometry;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.