@Override public RasterReader getRasterReader( String type ) { if ( type != null && FORMATS.contains( type.toLowerCase() ) ) { return new GridFileReader(); } return null; }
@Override public AbstractRaster load( File gridFile, RasterIOOptions options ) throws IOException { lastReadAccess = currentTimeMillis(); return super.load( gridFile, options ); }
@Override public BufferResult read( RasterRect rect, ByteBuffer resultBuffer ) throws IOException { BufferResult res = null; RasterRect fRect = snapToGrid( rect ); if ( fRect != null ) { int[] minCRmaxCR = getIntersectingTiles( fRect ); if ( minCRmaxCR == null ) { return null; } int size = fRect.width * fRect.height * sampleSize; if ( resultBuffer == null ) { resultBuffer = ByteBufferPool.allocate( size, false ); } synchronized ( LOCK ) { FileChannel channel = getFileChannel(); RasterRect tmpRect = new RasterRect( 0, 0, fRect.width, fRect.height ); for ( int col = minCRmaxCR[0]; col <= minCRmaxCR[2]; ++col ) { for ( int row = minCRmaxCR[1]; row <= minCRmaxCR[3]; ++row ) { readValuesFromTile( col, row, fRect, channel, resultBuffer ); } } res = new BufferResult( tmpRect, resultBuffer ); closeReadStream(); } } return res; }
public void dispose() { leaveStreamOpen( false ); try { closeReadStream(); } catch ( IOException e ) { if ( LOG.isDebugEnabled() ) { LOG.debug( "(Stack) Exception occurred: " + e.getLocalizedMessage(), e ); } else { LOG.error( "Exception occurred: " + e.getLocalizedMessage() ); } } }
@Override protected void read( int columnId, int rowId, ByteBuffer buffer ) throws IOException { int tileId = getTileId( columnId, rowId ); long begin = System.currentTimeMillis(); int tileInBlob = tileId % getTilesPerBlob(); // transfer the data from the blob try { synchronized ( LOCK ) { FileChannel channel = getFileChannel(); // MappedByteBuffer map = channel.map( MapMode.READ_ONLY, tileInBlob * getBytesPerTile(), // buffer.remaining() ); // buffer.put( map ); // map. // LOG.debug( "Tile id: {} -> pos in blob: {}", tileId, +tileInBlob ); channel.position( tileInBlob * getBytesPerTile() ); channel.read( buffer ); closeReadStream(); } // rewinding is not an option, buffer.rewind(); } catch ( IOException e ) { LOG.error( "Error reading tile data from blob: " + e.getMessage(), e ); } long elapsed = System.currentTimeMillis() - begin; if ( LOG.isDebugEnabled() ) { LOG.debug( "Loading of tile ({}x{}) in {} ms.", new Object[] { infoFile.getTileRasterWidth(), infoFile.getTileRasterHeight(), elapsed } ); } }
GridFileReader reader = new GridFileReader(); AbstractRaster filteredRaster = reader.load( tmpGridFile, options ); if ( !raster.isSimpleRaster() ) { List<AbstractRaster> tiles = ( (TiledRaster) raster ).getTileContainer().getTiles( raster.getEnvelope() );
instantiate( gridFile, options ); int expectedTilesPerBlob = (int) ( gridFile.length() / getBytesPerTile() ); if ( getTilesPerBlob() != expectedTilesPerBlob ) { LOG.error( "the number of tiles in the blob are wrong." ); super.setTilesPerBlob( expectedTilesPerBlob ); for ( int rowId = 0; rowId < infoFile.rows(); ++rowId ) { for ( int columnId = 0; columnId < infoFile.columns(); ++columnId ) { SimpleRaster rasterTile = (SimpleRaster) getTile( rowId, columnId ); if ( rasterTile != null ) { if ( noData != null ) {
int tileId = getTileId( tileColumn, tileRow ); long filePos = ( ( tileId % getTilesPerBlob() ) * getBytesPerTile() );
/** * Delete the file this cache reader is using. * * @return true if this cached reader no longer references an existing file. */ public boolean deleteCacheFile() { boolean result = true; synchronized ( LOCK ) { super.dispose(); File f = file(); if ( f != null ) { if ( f.exists() && f.isFile() ) { result = f.delete(); File metaInfo = GridMetaInfoFile.fileNameFromOptions( f.getParent(), FileUtils.getFilename( f ), null ); if ( metaInfo.exists() ) { boolean mR = metaInfo.delete(); if ( !mR ) { LOG.warn( "Could not delete meta info file for raster cache file: " + f.getAbsolutePath() ); } } } } } return result; }
@Override public String getDataLocationId() { return ( cachedReader != null ) ? cachedReader.getDataLocationId() : super.getDataLocationId(); }
@Override public RasterGeoReference getGeoReference() { return super.getGeoReference().createRelocatedReference( OriginLocation.OUTER ); }
/** * 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; }
this.blobReader = new SplittedBlobReader( blobDir, BLOB_FILE_NAME, BLOB_FILE_EXT, metaInfoFile ); } else { this.blobReader = new GridFileReader( metaInfoFile, files[0] );
/** * A gridded tile container which reads data from a deegree internal format. See d3_tools/RasterTreeGridifier on how * to create the format. This methods takes a single bob file instead of scanning a given directory * * @param blobFile * to read the tiles from. * @param metaInfoFile * @throws IOException */ public GriddedBlobTileContainer( File blobFile, GridMetaInfoFile metaInfoFile ) throws IOException { this( metaInfoFile ); if ( !blobFile.exists() ) { throw new IOException( "Given blobfile:" + blobFile + " does not exist." ); } long totalSize = blobFile.length(); LOG.debug( "Real blob size: " + totalSize ); // blobReaders = new GridFileReader[1]; blobReader = new GridFileReader( metaInfoFile, blobFile ); // tilesPerBlob = blobReader.getNumberOfTiles(); long expectedBlobSize = metaInfoFile.rows() * metaInfoFile.columns() * blobReader.getBytesPerTile(); if ( expectedBlobSize != totalSize ) { String msg = "Size of gridfile (=" + totalSize + ") does not match the expected size (=" + expectedBlobSize + ")."; throw new IllegalArgumentException( msg ); } }
reader = new GridFileReader( heixelFile, options ); return RasterDataFactory.createTiledRasterData( reader, options );
GridReader gr = new GridFileReader( cF, null ); imageBuffer = gr.getTileData( 0, 0, null ); if ( imageBuffer != null ) {