Examples of GridGeometry2D


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

      //
      // 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

            };
        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(getParameters(readParams, parameters,
                    true));
        return gc.getSampleDimensions();
    }   
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

        @Override
        protected void doMarshal(Object source,
                HierarchicalStreamWriter writer, MarshallingContext context) {
        
            GridGeometry2D g = (GridGeometry2D) source;
            MathTransform tx = g.getGridToCRS();

            writer.addAttribute("dimension", String.valueOf(g.getGridRange().getDimension()));
           
            //grid range
            StringBuffer low = new StringBuffer();
            StringBuffer high = new StringBuffer();
            for (int r = 0; r < g.getGridRange().getDimension(); r++) {
                low.append(g.getGridRange().getLow(r)).append(" ");
                high.append(g.getGridRange().getHigh(r)+1).append(" ");
            }
            low.setLength(low.length()-1);
            high.setLength(high.length()-1);
           
            writer.startNode("range");
            writer.startNode( "low" ); writer.setValue( low.toString() ); writer.endNode();
            writer.startNode( "high" ); writer.setValue( high.toString() ); writer.endNode();
            writer.endNode();
           
            //transform
            if (tx instanceof AffineTransform) {
                AffineTransform atx = (AffineTransform) tx;
               
                writer.startNode("transform");
                writer.startNode("scaleX"); writer.setValue(Double.toString( atx.getScaleX())); writer.endNode();
                writer.startNode("scaleY"); writer.setValue(Double.toString( atx.getScaleY())); writer.endNode();
                writer.startNode("shearX"); writer.setValue(Double.toString( atx.getShearX())); writer.endNode();
                writer.startNode("shearY"); writer.setValue(Double.toString( atx.getShearY())); writer.endNode();
                writer.startNode("translateX"); writer.setValue(Double.toString( atx.getTranslateX())); writer.endNode();
                writer.startNode("translateY"); writer.setValue(Double.toString( atx.getTranslateY())); writer.endNode();
                writer.endNode();
            }
           
            //crs
            writer.startNode("crs");
            context.convertAnother( g.getCoordinateReferenceSystem(),
                new SingleValueConverterWrapper( new SRSConverter() ) );
            writer.endNode();
          
        }
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

           
            // new grid range
            GeneralGridEnvelope gridRange = new GeneralGridEnvelope(low, high);
           
           
            GridGeometry2D gg = new GridGeometry2D( gridRange, gridToCRS, crs );
            return serializationMethodInvoker.callReadResolve(gg);
        }
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

            // and add the grid geometry info
            final Map parameters = CoverageUtils.getParametersKVP(reader.getFormat()
                    .getReadParameters());
            final GeneralEnvelope intersected = new GeneralEnvelope(destinationEnvelopeInSourceCRS);
            intersected.intersect(originalEnvelope);
            final GridGeometry2D destinationGridGeometry =new GridGeometry2D(PixelInCell.CELL_CENTER, gridToCRS, intersected, null);
            parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
                    destinationGridGeometry);
            coverage = (GridCoverage2D) reader.read(CoverageUtils.getParameters(reader.getFormat()
                    .getReadParameters(), parameters, true));
            if ((coverage == null) || !(coverage instanceof GridCoverage2D)) {
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

                    final CoverageInfo cinfo = requestedLayers[i].getCoverage();
                    final AbstractGridCoverage2DReader reader=(AbstractGridCoverage2DReader) cinfo.getGridCoverageReader(new NullProgressListener(),GeoTools.getDefaultHints());
                    final ParameterValueGroup params = reader.getFormat().getReadParameters();
                    final GeneralParameterValue[] parameters = CoverageUtils.getParameters(params, requestedLayers[i].getCoverage().getParameters(),true);
                    //get the original grid geometry
                    final GridGeometry2D coverageGeometry=(GridGeometry2D) cinfo.getGrid();
                    // set the requested position in model space for this request
                    final Coordinate middle = pixelToWorld(x, y, bbox, width, height);
                    DirectPosition position = new DirectPosition2D(requestedCRS, middle.x, middle.y);
                 
                  //change from request crs to coverage crs in order to compute a minimal request area,
                    // TODO this code need to be made much more robust
                    if (requestedCRS != null) {
                       
                        final CoordinateReferenceSystem targetCRS = coverageGeometry.getCoordinateReferenceSystem();
                        final TransformedDirectPosition arbitraryToInternal = new
                          TransformedDirectPosition(requestedCRS, targetCRS, new Hints(Hints.LENIENT_DATUM_SHIFT,Boolean.TRUE));
                        try {
                            arbitraryToInternal.transform(position);
                        } catch (TransformException exception) {
                            throw new CannotEvaluateException("Unable to answer the geatfeatureinfo",exception);
                        }
                        position=arbitraryToInternal;
                    }
                    //check that the provided point is inside the bbox for this coverage
                    if(!reader.getOriginalEnvelope().contains(position)) {
                        continue;
                    }
                   
                    //now get the position in raster space using the world to grid related to corner
                    final MathTransform worldToGrid=reader.getOriginalGridToWorld(PixelInCell.CELL_CORNER).inverse();
                    final DirectPosition rasterMid = worldToGrid.transform(position,null);
                    // create a 20X20 rectangle aruond the mid point and then intersect with the original range
                    final Rectangle2D.Double rasterArea= new Rectangle2D.Double();
                    rasterArea.setFrameFromCenter(rasterMid.getOrdinate(0), rasterMid.getOrdinate(1), rasterMid.getOrdinate(0)+10, rasterMid.getOrdinate(1)+10);
                    final Rectangle integerRasterArea=rasterArea.getBounds();
                    final GridEnvelope gridEnvelope=reader.getOriginalGridRange();
                    final Rectangle originalArea=
                      (gridEnvelope instanceof GridEnvelope2D)?
                          (GridEnvelope2D)gridEnvelope:
                          new Rectangle();
                    XRectangle2D.intersect(integerRasterArea, originalArea, integerRasterArea);
                    //paranoiac check, did we fall outside the coverage raster area? This should never really happne if the request is well formed.
                    if(integerRasterArea.isEmpty())
                      return;
                    // now set the grid geometry for this request
                    for(int k=0;k<parameters.length;k++){
                      if(!(parameters[k] instanceof Parameter<?>))
                        continue;
                     
                      final Parameter<?> parameter = (Parameter<?>) parameters[k];
                      if(parameter.getDescriptor().getName().equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName()))
                      {
                        //
                        //create a suitable geometry for this request reusing the getmap (we could probably optimize)
                        //
                        parameter.setValue(new GridGeometry2D(
                            new GridEnvelope2D(integerRasterArea),
                            reader.getOriginalGridToWorld(PixelInCell.CELL_CENTER),
                            reader.getCrs()
                            ));
                      }
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

                matrix[5] = tx.get( "translateY") != null ? tx.get( "translateY") : matrix[5];
                matrix[8] = 1.0;
               
                MathTransform gridToCRS = new DefaultMathTransformFactory()
                    .createAffineTransform( new GeneralMatrix(3,3,matrix));
                coverage.setGrid( new GridGeometry2D(range,gridToCRS,crs) );
            }
            else {
                coverage.setGrid( new GridGeometry2D( range, gridEnvelope ) );
            }
        }
        else {
            // new grid range
            GeneralGridEnvelope range = new GeneralGridEnvelope(new int[] { 0,
                    0 }, new int[] { 1, 1 });
            coverage.setGrid( new GridGeometry2D(range, gridEnvelope) );
        }
       
        for ( Iterator x = cInfoReader.coverageDimensions().iterator(); x   .hasNext(); ) {
            Map map = (Map) x.next();
            CoverageDimensionInfo cd = factory.createCoverageDimension();
View Full Code Here

Examples of org.geotools.coverage.grid.GridGeometry2D

                            // apply the bounds, taking into account the reprojection policy if need be
                            if (resourceInfo.getProjectionPolicy() == ProjectionPolicy.REPROJECT_TO_DECLARED && bounds != null) {
                                try {
                                    bounds = bounds.transform(resourceInfo.getCRS(), true);
                                    GridGeometry grid = ((CoverageInfo) resourceInfo).getGrid();
                                    ((CoverageInfo) resourceInfo).setGrid(new GridGeometry2D(grid.getGridRange(),grid.getGridToCRS(), resourceInfo.getCRS()));
                                } catch(Exception e) {
                                    throw (IOException) new IOException("transform error").initCause(e);
                                }
                            }
                        }
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.