/** * Set the default loading policy to one configured in the {@link RasterDataContainerFactory} * * @param ref * @param format * of the raster to read, e.g. png, jpg, tiff..., may be <code>null</code> */ public RasterIOOptions( RasterGeoReference ref, String format ) { this( ref ); if ( format != null && !"".equals( format ) ) { add( OPT_FORMAT, format ); } }
@Override public void write( OutputStream out ) throws IOException { RasterIOOptions options = new RasterIOOptions(); // lets fake GeoTiff until we have a real GeoTiff writer (TODO) if ( format.equalsIgnoreCase( "GeoTiff" ) ) { options.add( RasterIOOptions.OPT_FORMAT, "tiff" ); } else { options.add( RasterIOOptions.OPT_FORMAT, format ); } RasterFactory.saveRasterToStream( result, out, options ); }
/** * An empty constructor, nothing is set. The loading policy is the default value taken from the * {@link RasterDataContainerFactory}. Worldfile reading is on. */ public RasterIOOptions() { add( READ_WLD_FILE, "yes" ); add( DATA_LOADING_POLICY, RasterDataContainerFactory.getDefaultLoadingPolicy().name() ); }
/** * Return a RasterIOOption object with the format set according to the given file with an optional * {@link RasterGeoReference}. * * @param file * @param envelope * @return RasterIOOption proper format. */ public static RasterIOOptions forFile( File file, RasterGeoReference envelope ) { RasterIOOptions result = new RasterIOOptions( envelope ); String ext = FileUtils.getFileExtension( file ); result.add( OPT_FORMAT, ext ); result.add( READ_WLD_FILE, null ); return result; }
/** * Return a RasterIOOption object with the format set according to the given file. * * @param file * @return RasterIOOption proper format. */ public static RasterIOOptions forFile( File file ) { RasterIOOptions result = new RasterIOOptions(); String ext = FileUtils.getFileExtension( file ); result.add( OPT_FORMAT, ext ); return result; }
options.add( RasterIOOptions.OPT_FORMAT, inputType ); options.add( RasterIOOptions.CRS, crs ); if ( noDataType != DataType.UNDEFINED ) { byte[] noDatas = RasterIOOptions.createNoData( new String[] { noDataValue }, noDataType ); File cd = new File( cacheDir ); if ( cd.exists() && cd.isDirectory() ) { options.add( RasterIOOptions.RASTER_CACHE_DIR, cacheDir ); } else { LOG.warn( "Using default cache dir: " + RasterCache.DEFAULT_CACHE_DIR
dir = directory.getParentFile().getName() + "_" + directory.getName(); opts.add( RasterIOOptions.LOCAL_RASTER_CACHE_DIR, dir ); opts.add( RasterIOOptions.CREATE_RASTER_MISSING_CACHE_DIR, "yes" ); opts.add( RasterIOOptions.OPT_FORMAT, format ); boolean readSingleBlobTile = false; if ( format != null && ( "grid".equalsIgnoreCase( format ) || "bin".equalsIgnoreCase( format ) ) ) {
dir = directory.getParentFile().getName() + "_" + directory.getName(); opts.add( RasterIOOptions.LOCAL_RASTER_CACHE_DIR, dir ); opts.add( RasterIOOptions.CREATE_RASTER_MISSING_CACHE_DIR, "yes" ); opts.add( RasterIOOptions.OPT_FORMAT, format ); boolean readSingleBlobTile = false; if ( format != null && ( "grid".equalsIgnoreCase( format ) || "bin".equalsIgnoreCase( format ) ) ) {
/** * Save a raster to a file. * * @param raster * @param filename * @param options * map with options for the raster writer * @throws IOException */ public static void saveRasterToFile( AbstractRaster raster, File filename, RasterIOOptions options ) throws IOException { RasterIOOptions opts = new RasterIOOptions(); opts.copyOf( options ); if ( !opts.contains( RasterIOOptions.OPT_FORMAT ) ) { String format = FileUtils.getFileExtension( filename ); opts.add( RasterIOOptions.OPT_FORMAT, format ); } RasterWriter writer = getRasterWriter( raster, opts ); if ( writer == null ) { log.error( "couldn't find raster writer for " + filename ); throw new IOException( "couldn't find raster writer" ); } writer.write( raster, filename, options ); }
rOptions.copyOf( options ); if ( config.getOriginLocation() != null ) { rOptions.add( RasterIOOptions.GEO_ORIGIN_LOCATION, config.getOriginLocation().toString().toUpperCase() ); rOptions.add( RasterIOOptions.IMAGE_INDEX, imageIndex.toString() ); boolean recursive = directory.isRecursive(); if ( crs != null ) { rOptions.add( RasterIOOptions.CRS, crs.getAlias() ); return null; rOptions.add( RasterIOOptions.OPT_FORMAT, file.substring( file.lastIndexOf( '.' ) + 1 ) ); AbstractRaster raster = loadRasterFromFile( loc, rOptions, metadata ); if ( raster != null ) {
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 ); } }