private IIORasterDataReader( RasterIOOptions options, boolean resetableStream, int imageIndex ) { this.imageIndex = imageIndex; this.format = options.get( RasterIOOptions.OPT_FORMAT ); this.options = options; this.resetableStream = resetableStream; }
@Override public boolean canWrite( AbstractRaster raster, RasterIOOptions options ) { String format = options.get( RasterIOOptions.OPT_FORMAT ); if ( "geotiff".equalsIgnoreCase( format ) ) { format = "tiff"; } if ( ImageIO.getImageWritersBySuffix( format ).hasNext() ) { return true; } return false; }
private void setID( RasterIOOptions options ) { this.dataLocationId = options != null ? options.get( RasterIOOptions.ORIGIN_OF_RASTER ) : null; if ( dataLocationId == null ) { if ( this.file != null ) { this.dataLocationId = FileUtils.getFilename( this.file ); } } }
private void setID( RasterIOOptions options ) { this.dataLocationId = options != null ? options.get( RasterIOOptions.ORIGIN_OF_RASTER ) : null; if ( dataLocationId == null ) { if ( this.file != null ) { this.dataLocationId = FileUtils.getFilename( this.file ); } } }
private void setID( RasterIOOptions options ) { this.dataLocationId = options != null ? options.get( RasterIOOptions.ORIGIN_OF_RASTER ) : null; if ( dataLocationId == null ) { if ( this.file != null ) { this.dataLocationId = FileUtils.getFilename( this.file ); } } }
/** * find a filename from the given options or create a 'default-file-name' in the given directory. * * @param defaultDir * to use if the options do not contain a file, a file named gridded_raster.info * {@link GridMetaInfoFile#METAINFO_FILE_NAME} will be created. * @param filename * if no name could be read from the options, use the given filename. * @param options * to get the file for the given grid meta info. * @return a file defined by the given options or the default filename in the given directory. */ public static File fileNameFromOptions( String defaultDir, String filename, RasterIOOptions options ) { String metaFile = options == null ? null : options.get( METAINFO_FILE ); if ( metaFile == null ) { if ( filename == null ) { metaFile = defaultDir + File.separator + METAINFO_FILE_NAME; } else { metaFile = defaultDir + File.separator + filename; } } if ( !metaFile.endsWith( METAINFO_FILE_EXT ) ) { metaFile += "." + METAINFO_FILE_EXT; } return new File( metaFile ); }
/** * Gets an instance of a data cache which uses the given options to instantiate a cache. Currently following * {@link RasterIOOptions} keys are evaluated. If the options are <code>null</code> the {@link #DEFAULT_CACHE_DIR} * will be used. * <ul> * <li>{@link RasterIOOptions#RASTER_CACHE_DIR}</li> * <li>{@link RasterIOOptions#LOCAL_RASTER_CACHE_DIR}</li> * <li>{@link RasterIOOptions#CREATE_RASTER_MISSING_CACHE_DIR}</li> * </ul> * * @param options * which can contain cache information. * @return a raster cache for the given directory. */ public static RasterCache getInstance( RasterIOOptions options ) { File directory = DEFAULT_CACHE_DIR; boolean create = false; if ( options != null ) { String topLevelDir = options.get( RasterIOOptions.RASTER_CACHE_DIR ); if ( topLevelDir != null ) { directory = new File( topLevelDir ); } String dir = options.get( RasterIOOptions.LOCAL_RASTER_CACHE_DIR ); if ( dir != null ) { directory = new File( directory, dir ); } create = options.get( RasterIOOptions.CREATE_RASTER_MISSING_CACHE_DIR ) != null; } return getInstance( directory, create ); }
@Override public AbstractRaster load( InputStream stream, RasterIOOptions options ) throws IOException { String imageIndex = options.get( RasterIOOptions.IMAGE_INDEX ); reader = new IIORasterDataReader( stream, options, imageIndex == null ? 0 : Integer.parseInt( imageIndex ) ); return loadFromReader( reader, options ); }
@Override public AbstractRaster load( File file, RasterIOOptions options ) throws IOException { String imageIndex = options.get( RasterIOOptions.IMAGE_INDEX ); LOG.debug( "reading " + file + " with ImageIO" ); reader = new IIORasterDataReader( file, options, imageIndex == null ? 0 : Integer.parseInt( imageIndex ) ); AbstractRaster r = loadFromReader( reader, options ); return r; }
private static RasterReader getRasterReader( RasterIOOptions options ) { for ( RasterIOProvider reader : getRasterIOLoader() ) { String format = options.get( RasterIOOptions.OPT_FORMAT ); RasterReader possibleReader = reader.getRasterReader( format ); if ( possibleReader != null ) { return possibleReader; } } return null; }
private static RasterReader getRasterReader( File filename, RasterIOOptions options ) { for ( RasterIOProvider reader : getRasterIOLoader() ) { String format = options.get( RasterIOOptions.OPT_FORMAT ); if ( format == null ) { String nm = filename.getName(); format = nm.substring( nm.lastIndexOf( '.' ) + 1 ); } RasterReader possibleReader = reader.getRasterReader( format ); if ( possibleReader != null && possibleReader.canLoad( filename ) ) { return possibleReader; } } return null; }
@Override public void write( AbstractRaster raster, OutputStream out, RasterIOOptions options ) throws IOException { LOG.debug( "writing to stream with ImageIO" ); String format = options != null ? options.get( RasterIOOptions.OPT_FORMAT ) : null; if ( "geotiff".equals( format ) ) { GeoTiffWriter.save( raster, out ); } else { IIORasterDataWriter.saveRasterDataToStream( raster.getAsSimpleRaster().getRasterData(), out, format ); } }
private static RasterWriter getRasterWriter( AbstractRaster raster, RasterIOOptions options ) { for ( RasterIOProvider writer : getRasterIOLoader() ) { String format = options.get( RasterIOOptions.OPT_FORMAT ); RasterWriter possibleWriter = writer.getRasterWriter( format ); // TODO if ( possibleWriter != null && possibleWriter.canWrite( raster, options ) ) { return possibleWriter; } } return null; }
private void setID( RasterIOOptions options ) { this.dataLocationId = options != null ? options.get( RasterIOOptions.ORIGIN_OF_RASTER ) : null; if ( dataLocationId == null ) { if ( reader != null && reader.file() != null ) { this.dataLocationId = FileUtils.getFilename( reader.file() ); } } }
/** * @param options * @throws IOException * @throws NumberFormatException */ private synchronized void instantiate( File gridFile, RasterIOOptions options ) throws NumberFormatException, IOException { if ( infoFile == null && gridFile != null ) { this.dataLocationId = options == null ? FileUtils.getFilename( gridFile ) : options.get( RasterIOOptions.ORIGIN_OF_RASTER ); File metaInfo = GridMetaInfoFile.fileNameFromOptions( gridFile.getParent(), FileUtils.getFilename( gridFile ), options ); this.instantiate( GridMetaInfoFile.readFromFile( metaInfo, options ), gridFile ); } }
@Override public void write( AbstractRaster raster, File file, RasterIOOptions options ) throws IOException { LOG.debug( "writing " + file + " with ImageIO" ); String format = options != null ? options.get( RasterIOOptions.OPT_FORMAT ) : null; if ( format == null ) { format = FileUtils.getFileExtension( file ); } LOG.debug( "Writing raster with width: {} height: {}", raster.getColumns(), raster.getRows() ); if ( "geotiff".equals( format ) ) { GeoTiffWriter.save( raster, file ); } else { IIORasterDataWriter.saveRasterDataToFile( raster.getAsSimpleRaster().getRasterData(), file, format ); RasterGeoReference rasterReference = raster.getRasterReference(); WorldFileAccess.writeWorldFile( rasterReference, file ); } }
@Override public void write( AbstractRaster raster, OutputStream out, RasterIOOptions options ) throws IOException { LOG.debug( "writing to stream with JAI" ); String ext = options.get( RasterIOOptions.OPT_FORMAT ); String format = JAIRasterIOProvider.getJAIFormat( ext ); if ( format != null ) { JAIRasterDataWriter.saveRasterDataToStream( raster.getAsSimpleRaster().getRasterData(), out, format ); } else { JAIRasterDataWriter.saveRasterDataToStream( raster.getAsSimpleRaster().getRasterData(), out, "TIFF" ); } }
DataType type = data.getDataType(); String newLine = System.getProperty( "line.separator" ); String separator = options.get( XYZRasterIOProvider.XYZ_SEPARATOR ); if ( separator == null ) { separator = " ";