/** * Create a Gird for the given pixel resolution and output envelope * * @param resx * resolution of a pixel (ie. the width of each grid cell in CRS units) * @param resy * resolution of a pixel (ie. the height of each grid cell in CRS units) * @param resz * resolution of a pixel (ie. the depth of each grid cell in CRS units) * @param targetEnvelope * the envelope of the output grid * @return a new grid */ public static Grid fromRes( double resx, double resy, double resz, Envelope targetEnvelope ) { int width = (int) Math.round( targetEnvelope.getSpan0() / resx ); int height = (int) Math.round( targetEnvelope.getSpan1() / resy ); int depth = Integer.MIN_VALUE; if ( !Double.isNaN( resz ) ) { if ( targetEnvelope.getCoordinateDimension() == 3 ) { double envDepth = getEnvDepth( targetEnvelope ); depth = (int) Math.round( envDepth / resz ); } } return new Grid( width, height, depth, targetEnvelope ); }
FeatureCollection handleFeatureInfo() { try { SimpleRaster res = transform( raster, bbox, Grid.fromSize( 1, 1, MAX_VALUE, bbox ), interpol.toString() ).getAsSimpleRaster(); RasterData data = res.getRasterData(); GenericFeatureCollection col = new GenericFeatureCollection();
/** * Returns a subset of the raster, transformed into to SRS of the target envelope. * * @param raster * @param env * @param grid * @param interpolation * @return the transformation result * @throws TransformationException * if the transformation fails */ public static AbstractRaster transform( AbstractRaster raster, Envelope env, Grid grid, String interpolation ) throws TransformationException { LOG.debug( "Transforming raster with envelope '{}' and grid '{}', interpolation method '{}'.", new Object[] { env, grid, interpolation } ); AbstractRaster result; try { RasterTransformer transf = new RasterTransformer( env.getCoordinateSystem() ); result = transf.transform( raster, env, grid.getWidth(), grid.getHeight(), InterpolationType.fromString( interpolation ) ); } catch ( Exception e ) { LOG.debug( "Original stack trace", e ); throw new TransformationException( "error while transforming raster result: " + e.getMessage(), e ); } return result; } }
/** * Create a Gird for the given grid size and output envelope * * @param width * the width of the grid in pixel * @param height * the height of the grid in pixel * @param depth * the depth of the grid in pixel * @param targetEnvelope * the envelope of the output grid * @return a new grid */ public static Grid fromSize( int width, int height, int depth, Envelope targetEnvelope ) { return new Grid( width, height, depth, targetEnvelope ); }
/** * @return the lowest resolution of the grid */ public double getResolution() { double xRes = targetEnvelope.getSpan0() / width; double yRes = targetEnvelope.getSpan1() / height; double zRes = Double.MAX_VALUE; if ( depth != Integer.MIN_VALUE ) { double envDepth = getEnvDepth( targetEnvelope ); if ( !Double.isNaN( envDepth ) ) { zRes = envDepth / depth; } } return min( xRes, min( yRes, zRes ) ); }
@Override public CoverageResult getCoverageResult( Envelope env, Grid grid, String format, String interpolation, RangeSet requestedRangeset ) throws WCServiceException { AbstractRaster rasterLevel = ( (MultiResolutionRaster) coverage ).getRaster( grid.getResolution() ); AbstractRaster result; try { result = CoverageTransform.transform( rasterLevel, env, grid, interpolation ); } catch ( TransformationException e ) { throw new RuntimeException( "error while transforming raster result: " + e.getMessage(), e ); } if ( requestedRangeset != null ) { RasterFilter filter = new RasterFilter( result ); result = filter.apply( getRangeSet(), requestedRangeset ); } return new SimpleRasterResult( result, format ); }
result = CoverageTransform.transform( raster, bbox, Grid.fromSize( width, height, MAX_VALUE, bbox ), interpol.toString() );
return Grid.fromSize( width, height, depth, targetEnvelope );