/** * Get interpolation for the given string. This method is case insensitive, words can be separated with a * whitespace, minus or underscore. * * @param interpolation * @return the interpolation */ public static InterpolationType fromString( String interpolation ) { String key = interpolation.toUpperCase(); key = key.replaceAll( "-", "_" ); key = key.replaceAll( "\\s", "_" ); return InterpolationType.valueOf( key ); } }
/** * @return this WCS interpolation type as a raster api type, or <code>null</code> if it the interpolation * method is not supported by the raster api. */ public InterpolationType asRasterAPIType() { return InterpolationType.fromString( name() ); } }
return new NearestNeighborInterpolation( rasterData ); } else if ( type == BILINEAR ) { if ( rasterData.getDataType() == DataType.BYTE ) { return new BiLinearByteInterpolation( rasterData ); } else if ( rasterData.getDataType() == DataType.FLOAT ) { return new BiLinearFloatInterpolation( rasterData ); } else if ( rasterData.getDataType() == DataType.SHORT ) { return new BiLinearShortInterpolation( rasterData, false ); } else if ( rasterData.getDataType() == DataType.USHORT ) { return new BiLinearShortInterpolation( rasterData, true ); } else { throw new UnsupportedOperationException( "no bilinear interpolation implementation for "
/** * Interpolates the given raster to retrieve a raster with the given width and height. * * @param sourceRaster * the raster to get an interpolation version from * @param dstWidth * the width (columns) of the resulting raster * @param dstHeight * the height (rows) of the resulting raster * @return the interpolated raster */ public AbstractRaster interPolate( AbstractRaster sourceRaster, int dstWidth, int dstHeight ) { SimpleRaster simpleSourceRaster = sourceRaster.getAsSimpleRaster(); RasterData srcData = simpleSourceRaster.getReadOnlyRasterData(); RasterGeoReference srcREnv = simpleSourceRaster.getRasterReference(); // interpolation is needed. Interpolation interpolation = InterpolationFactory.getInterpolation( interpolationType, srcData ); RasterRect rr = new RasterRect( 0, 0, dstWidth, dstHeight ); RasterData dstData = srcData.createCompatibleWritableRasterData( rr, null ); RasterGeoReference dstREnv = RasterGeoReference.create( sourceRaster.getRasterReference().getOriginLocation(), sourceRaster.getEnvelope(), dstWidth, dstHeight ); // use warp to calculate the correct sample positions in the source raster. // the warp is a cubic polynomial function created of 100 points in the dstEnvelope. This function will map // points from the source crs to the target crs very accurate. WarpPolynomial warp = createWarp( dstWidth, dstHeight, srcREnv, dstREnv ); warpTransform( warp, interpolation, dstData ); return new SimpleRaster( dstData, sourceRaster.getEnvelope(), dstREnv, (ResourceMetadata) sourceRaster.getMetadata() ); }
RasterInterpolater interpolater = new RasterInterpolater( interpolation ); return interpolater.interPolate( this.getSubRaster( spatialExtent ), rect.width, rect.height );
private String getInterpolation() { return getNodeAsString( rootElement, new XPath( "/" + WCS_PREFIX + ":GetCoverage/" + WCS_PREFIX + ":interpolationMethod", wcsNSContext ), InterpolationType.NEAREST_NEIGHBOR.name() ); }
/** * @param warp * @param interpolation * @param dstData */ private void warpTransform( WarpPolynomial warp, Interpolation interpolation, RasterData dstData ) { byte[] pixel = new byte[dstData.getBands() * dstData.getDataType().getSize()]; float[] srcCoords = new float[dstData.getColumns() * 2]; for ( int y = 0; y < dstData.getRows(); y++ ) { // look-up the pixel positions in the source raster for every pixel in this row, the srcCoords will contain // the x,y ([2n],[2n+1]) values in the source raster (defined in the native CRS) for this row of pixels. warp.warpRect( 0, y, dstData.getColumns(), 1, srcCoords ); for ( int x = 0; x < dstData.getColumns(); x++ ) { // get the interpolated pixel and set the value into the result raster interpolation.getPixel( srcCoords[x * 2], srcCoords[x * 2 + 1], pixel ); dstData.setPixel( x, y, pixel ); } } }
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();
Interpolation interpolation = InterpolationFactory.getInterpolation( interpolationType, srcData );
private static void checkOutputOptions( GetCoverage request, CoverageOptions options ) throws OWSException { boolean supported; String outputFormat = request.getOutputFormat(); supported = options.getOutputFormats().contains( outputFormat ); if ( !supported ) { // check for geotiff if ( outputFormat == null || !"geotiff".equals( outputFormat.toLowerCase() ) ) { throw new OWSException( "Unsupported output format (" + outputFormat + ")", OWSException.INVALID_PARAMETER_VALUE, "FORMAT" ); } } String interpolation = request.getInterpolation(); try { supported = options.getInterpolations().contains( InterpolationType.fromString( interpolation ) ); } catch ( Exception e ) { throw new OWSException( "Unsupported interpolation (" + interpolation + ")", OWSException.INVALID_PARAMETER_VALUE, "INTERPOLATION" ); } String crs = request.getOutputCRS(); supported = options.getCRSs().contains( crs ); if ( !supported ) { throw new OWSException( "unsupported response crs (" + crs + ")", OWSException.INVALID_PARAMETER_VALUE, "RESPONSE CRS" ); } }
String interpolation = getDefault( kvp, "INTERPOLATION", InterpolationType.NEAREST_NEIGHBOR.name() );
/** * @param warp * @param interpolation * @param dstData */ private void warpTransform( WarpPolynomial warp, Interpolation interpolation, RasterData dstData ) { byte[] pixel = new byte[dstData.getBands() * dstData.getDataType().getSize()]; float[] srcCoords = new float[dstData.getColumns() * 2]; for ( int y = 0; y < dstData.getRows(); y++ ) { // look-up the pixel positions in the source raster for every pixel in this row, the srcCoords will contain // the x,y ([2n],[2n+1]) values in the source raster (defined in the native CRS) for this row of pixels. warp.warpRect( 0, y, dstData.getColumns(), 1, srcCoords ); for ( int x = 0; x < dstData.getColumns(); x++ ) { // get the interpolated pixel and set the value into the result raster interpolation.getPixel( srcCoords[x * 2], srcCoords[x * 2 + 1], pixel ); dstData.setPixel( x, y, pixel ); } } }
interpol.toString() );
/** * 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; } }