/** * 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() ); }
Interpolation interpolation = InterpolationFactory.getInterpolation( interpolationType, srcData );