@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 ); }
/** * 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 ); }
/** * Load a raster from a file. * * @param filename * the filename of the raster * @return the loaded raster as an AbstractRaster * @throws IOException */ public static AbstractRaster loadRasterFromFile( File filename ) throws IOException { RasterIOOptions options = RasterIOOptions.forFile( filename ); return loadRasterFromFile( filename, options, null ); }
if ( getLoadingPolicy() != otherOptions.getLoadingPolicy() ) { add( DATA_LOADING_POLICY, otherOptions.getLoadingPolicy().name() ); if ( readWorldFile() != otherOptions.readWorldFile() ) { add( READ_WLD_FILE, otherOptions.readWorldFile() + "" ); if ( getRasterGeoReference() == null ) { setRasterGeoReference( otherOptions.getRasterGeoReference() ); setNoData( otherOptions.getNoDataValue() ); if ( getRasterOriginLocation() == OriginLocation.CENTER ) { add( GEO_ORIGIN_LOCATION, otherOptions.getRasterOriginLocation().name() ); if ( getCRS() == null && otherOptions.getCRS() != null ) { add( CRS, otherOptions.getCRS().getAlias() ); String val = otherOptions.get( key ); if ( val != null && options.get( key ) == null ) { options.put( key, val );
private AbstractRaster loadFromReader( IIORasterDataReader reader, RasterIOOptions options ) { width = reader.getColumns(); height = reader.getRows(); RasterIOOptions opts = new RasterIOOptions(); opts.copyOf( options ); setID( opts ); OriginLocation definedRasterOrigLoc = opts.getRasterOriginLocation(); String imageIndex = opts.get( RasterIOOptions.IMAGE_INDEX ); int factor = 0; if ( imageIndex != null ) { if ( opts.hasRasterGeoReference() ) { rasterReference = opts.getRasterGeoReference(); } else { if ( opts.readWorldFile() ) { try { if ( reader.file() != null ) { readCRS = opts.getCRS(); } else { readCRS = CRSManager.getCRSRef( crs );
LOG.debug( "Found following files: \n{}", coverageFiles.toString() ); RasterIOOptions opts = new RasterIOOptions(); opts.copyOf( options ); String cacheDir = opts.get( RasterIOOptions.LOCAL_RASTER_CACHE_DIR ); if ( cacheDir == null ) { String dir = directory.getName(); dir = directory.getParentFile().getName() + "_" + directory.getName(); opts.add( RasterIOOptions.LOCAL_RASTER_CACHE_DIR, dir ); if ( opts.get( RasterIOOptions.CREATE_RASTER_MISSING_CACHE_DIR ) == null ) { 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 ) ) ) {
DataType noDataType = DataType.fromString( dataType ); RasterIOOptions options = new RasterIOOptions( originLocation ); options.add( RasterIOOptions.OPT_FORMAT, inputType ); options.add( RasterIOOptions.CRS, crs ); if ( noDataType != DataType.UNDEFINED ) { byte[] noDatas = RasterIOOptions.createNoData( new String[] { noDataValue }, noDataType ); options.setNoData( noDatas ); options.add( RasterIOOptions.RASTER_CACHE_DIR, cacheDir ); } else { LOG.warn( "Using default cache dir: " + RasterCache.DEFAULT_CACHE_DIR
final RasterIOOptions options = new RasterIOOptions(); options.copyOf( this.rasterOptions ); options.add( RasterIOOptions.CRS, dstSRS.getAlias() ); options.add( RasterIOOptions.OPT_FORMAT, outputFormat );
private IIORasterDataReader( RasterIOOptions options, boolean resetableStream, int imageIndex ) { this.imageIndex = imageIndex; this.format = options.get( RasterIOOptions.OPT_FORMAT ); this.options = options; this.resetableStream = resetableStream; }
if ( options.getNoDataValue() == null ) { byte[] createNoData = RasterIOOptions.createNoData( new String[] { Double.toString( noData ) }, DataType.FLOAT ); options.setNoData( createNoData ); if ( origLoc != OriginLocation.OUTER && options.getRasterOriginLocation() == OriginLocation.OUTER ) { Envelope rasterEnvelope = this.geoReference.getEnvelope( width, height, options.getCRS() ); RasterData data = RasterDataFactory.createRasterData( width, height, rdi, geoReference, buffer, true, FileUtils.getFilename( this.file ), options );
RasterGeoReference rasterReference = null; ICRS crs = options == null ? null : options.getCRS(); if ( crs == null ) { LOG.warn( "Configured crs is null, maybe the rasterfiles define one." ); try { LOG.info( "Creating raster from file: {}", filename ); RasterIOOptions newOpts = RasterIOOptions.forFile( filename ); newOpts.copyOf( options ); AbstractRaster raster = RasterFactory.loadRasterFromFile( filename, newOpts ); ICRS rasterCRS = raster.getCoordinateSystem();
RasterIOOptions opts = options; if ( opts == null ) { opts = new RasterIOOptions( ref ); } else { RasterGeoReference defRef = options.getRasterGeoReference(); if ( defRef != null ) { ref = defRef; } else { options.setRasterGeoReference( ref );
GridFileReader reader = new GridFileReader(); RasterIOOptions options = new RasterIOOptions(); options.setNoData( noDatas ); AbstractRaster filteredRaster = reader.load( tmpGridFile, options ); if ( !raster.isSimpleRaster() ) {
RasterIOOptions nOpts = options; if ( nOpts == null ) { nOpts = RasterIOOptions.forFile( filename ); if ( nOpts != null && nOpts.readWorldFile() ) { try { RasterGeoReference geoRef = WorldFileAccess.readWorldFile( filename, nOpts ); nOpts.setRasterGeoReference( geoRef ); } catch ( IOException e ) { LOG.debug( "Could not read xyz world file: " + e.getLocalizedMessage(), e ); if ( result != null && nOpts != null && nOpts.getNoDataValue() != null ) { result.getRasterData().setNoDataValue( nOpts.getNoDataValue() );
private AbstractRaster loadFromReader( JAIRasterDataReader reader, RasterIOOptions options ) { width = reader.getColumns(); height = reader.getRows(); setID( options ); reader.close(); OriginLocation definedRasterOrigLoc = options.getRasterOriginLocation(); // create a 1:1 mapping rasterReference = new RasterGeoReference( definedRasterOrigLoc, 1, -1, 0.5, height - 0.5 ); if ( options.hasRasterGeoReference() ) { rasterReference = options.getRasterGeoReference(); } else { if ( options.readWorldFile() ) { try { if ( file != null ) { rasterReference = WorldFileAccess.readWorldFile( file, options ); } } catch ( IOException e ) { // } } } Envelope envelope = rasterReference.getEnvelope( width, height, null ); // RasterDataContainer source = RasterDataContainerFactory.withDefaultLoadingPolicy( reader ); // RasterDataContainer source = RasterDataContainerFactory.withLoadingPolicy( reader, options.getLoadingPolicy() // ); RasterDataInfo rdi = reader.getRasterDataInfo(); return RasterFactory.createEmptyRaster( rdi, envelope, rasterReference, this, true, options ); }
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 ); } }
/** * Save a raster to a file. * * @param raster * @param filename * @throws IOException */ public static void saveRasterToFile( AbstractRaster raster, File filename ) throws IOException { saveRasterToFile( raster, filename, new RasterIOOptions() ); }
ICRS crs = null; if ( options != null ) { location = options.getRasterOriginLocation(); crs = options.getCRS();
/** * 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 ); } }
geoReference = options.getRasterGeoReference(); gridExtension.maxy, options.getCRS() ); int[] size = geoReference.getSize( rasterEnvelope ); width = size[0];