/** * 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; } }
private static void transformRaster( String[] args, String srcCRS, String dstCRS, InterpolationType type, OriginLocation location ) { try { MemoryTileContainer tileContainer = new MemoryTileContainer(); for ( int i = 0; i < args.length - 1; i++ ) { if ( args[i] != null ) { File f = new File( args[i] ); RasterIOOptions options = RasterIOOptions.forFile( f ); options.add( RasterIOOptions.GEO_ORIGIN_LOCATION, location.name() ); tileContainer.addTile( RasterFactory.loadRasterFromFile( f, options ) ); } } AbstractRaster srcRaster = new TiledRaster( tileContainer, null ); RasterTransformer transf = new RasterTransformer( dstCRS ); srcRaster.setCoordinateSystem( CRSManager.getCRSRef( srcCRS ) ); AbstractRaster result = transf.transform( srcRaster, type ); RasterFactory.saveRasterToFile( result, new File( args[args.length - 1] ) ); } catch ( Exception ex ) { System.err.println( "Couldn't transform raster file: " ); ex.printStackTrace(); System.exit( 2 ); } }
int reqHeight = height; RasterTransformer rtrans = new RasterTransformer( bbox.getCoordinateSystem() ); if ( bbox.getCoordinateSystem() != null && !bbox.getCoordinateSystem().equals( srs ) ) { LOG.debug( "Transforming bbox {} to {}.", bbox, srs );
throws IllegalArgumentException, UnknownCRSException, IOException { final RasterTransformer transf = new RasterTransformer( dstSRS ); transf.setBackgroundValue( backgroundValue );
RasterTransformer transformer = new RasterTransformer( targetCRS ); result = transformer.transform( this, spatialExtent, rect.width, rect.height, interpolation ); } catch ( TransformationException e ) {