@Override public String getDataLocationId() { return ( cachedReader != null ) ? cachedReader.getDataLocationId() : super.getDataLocationId(); }
/** * Load a raster from a stream. * * @param in * @param options * map with options for the raster writer * @return the loaded raster as an AbstractRaster * @throws IOException */ public static AbstractRaster loadRasterFromStream( InputStream in, RasterIOOptions options ) throws IOException { RasterReader reader = getRasterReader( options ); if ( reader == null ) { log.error( "couldn't find raster reader for stream" ); throw new IOException( "couldn't find raster reader for stream (" + options + ")" ); } return reader.load( in, options ); }
/** * Set the memory buffer to null and call dispose on the reader as well. */ public void dispose() { synchronized ( LOCK ) { if ( data != null ) { data = null; } if ( reader != null ) { reader.dispose(); } } }
/** * @param cachedReader * @param cacheFile * @param cache * */ public CacheRasterReader( RasterReader cachedReader, File cacheFile, RasterCache cache ) { this( cachedReader.getWidth(), cachedReader.getHeight(), cacheFile, cachedReader.shouldCreateCacheFile(), cachedReader.getRasterDataInfo(), cachedReader.getGeoReference(), cache ); this.cachedReader = cachedReader; // rb: instantiate on load may not be the wanted thing. // if ( this.cachedReader != null && !this.cachedReader.canReadTiles() ) { // BufferResult result = null; // try { // result = this.cachedReader.read( new RasterRect( 0, 0, this.cachedReader.getWidth(), // this.cachedReader.getHeight() ), null ); // } catch ( IOException e ) { // LOG.warn( "Could not create tiles from the reader because; {}", e.getLocalizedMessage(), e ); // // e.printStackTrace(); // } // if ( result != null ) { // createTilesFromFilledBuffer( result.getResult(), result.getRect().width, result.getRect().height ); // } // result = null; // } }
/** * Adds a raster reader to this cache, all cache files will be written to this cache directory. * * @param reader * to add to the cache. * @return a new CachedReader which was added to the cache. */ public RasterReader addReader( RasterReader reader ) { CacheRasterReader result = null; if ( reader != null ) { if ( reader instanceof CacheRasterReader ) { result = (CacheRasterReader) reader; } else { boolean createCache = reader.shouldCreateCacheFile(); File cacheFile = null; if ( createCache ) { cacheFile = createCacheFile( reader.getDataLocationId() ); } result = new CacheRasterReader( reader, cacheFile, this ); } addReader( result ); } else { LOG.debug( "Not adding reader to cache, because it is was null." ); } if ( LOG.isDebugEnabled() && result != null && reader != null ) { LOG.debug( "Adding reader to cache {} with id: {}.", reader, reader.getDataLocationId() ); } return result; }
SimpleRaster simpleRaster = tiles.get( 0 ); RasterReader rasterReader = ( (ByteBufferRasterData) simpleRaster.getRasterData() ).getReader(); File file = rasterReader.file(); File outputLocation = getOutputLocation( file, outLoc, outputFormat, tiles.size() == 1 ); ByteBufferRasterData data = (ByteBufferRasterData) tile.getRasterData(); RasterReader origReader = data.getReader(); final String tileName = origReader.getDataLocationId(); if ( tiles.size() == 1 ) { if ( outputLocation.isFile() ) {
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; }
String id = origReader.getDataLocationId(); File outputFile = new File( outputDir, id + "." + outputType ); RasterFactory.saveRasterToFile( subRaster, outputFile ); Envelope env = raster.getEnvelope(); AbstractRaster subRaster = filteredRaster.getSubRaster( env ); String id = origReader.getDataLocationId(); File outputFile = new File( outputDir, id + "." + outputType ); RasterFactory.saveRasterToFile( subRaster, outputFile );
/** * Load a raster from a file. * * @param filename * the filename of the raster * @param options * @return the loaded raster as an AbstractRaster * @throws IOException */ public static AbstractRaster loadRasterFromFile( File filename, RasterIOOptions options, ResourceMetadata<Coverage> metadata ) throws IOException { RasterReader reader = getRasterReader( filename, options ); if ( reader == null ) { log.error( "couldn't find raster reader for " + filename ); throw new IOException( "couldn't find raster reader" ); } AbstractRaster cov = reader.load( filename, options ); cov.setMetadata( metadata ); return cov; }
/** * Causes the cachefile to be written (if existing) and the memory buffers to be set to null. * * @param memoryBuffersAsWell * if true the memorybuffers (the ones which don't have rasterfiles to back them up) will be deleted as * well. * * @return the amount of freed memory. */ public long dispose( boolean memoryBuffersAsWell ) { if ( cachedReader != null ) { // close the file in the reader as well. cachedReader.dispose(); super.dispose(); } long result = 0; if ( gridWriter != null ) { result = writeCache( true ); } else { if ( memoryBuffersAsWell ) { clear( false ); } } return result; }
/** * loads the raster * * @param tileBaseDir * @return the loaded simpleraster * @throws IOException */ public AbstractRaster loadRaster( String tileBaseDir ) throws IOException { File file = new File( getFullFileName( tileBaseDir ) ); RasterReader reader = new IIORasterReader(); RasterIOOptions options = RasterIOOptions.forFile( file, getEnvelope() ); return reader.load( file, options ); }