/** * @param column * @param row * @param buffer * @return a newly allocated buffer if the given one was <code>null</code> * @throws IOException */ public ByteBuffer getTileData( int column, int row, ByteBuffer buffer ) throws IOException { if ( buffer == null ) { buffer = allocateTileBuffer( false, false ); } read( column, row, buffer ); return buffer; }
@Override public boolean canLoad( File filename ) { return originalReader.canLoad( filename ); }
@Override public boolean canReadTiles() { return originalReader.canReadTiles(); }
/** * @param reader * to be used for the tiles. * @param options * */ protected TiledRasterData( GridReader reader, RasterIOOptions options ) { if ( reader == null ) { throw new NullPointerException( "Grid reader may not be null." ); } this.columns = reader.getTileColumns(); this.rows = reader.getTileRows(); this.tileWidth = reader.getTileRasterWidth(); this.tileHeight = reader.getTileRasterHeight(); tiles = new RasterData[this.columns * this.rows]; for ( int row = 0; row < rows; ++row ) { for ( int col = 0; col < columns; ++col ) { TileOffsetReader r = new TileOffsetReader( reader, new RasterRect( col * tileWidth, row * tileHeight, tileWidth, tileHeight ) ); tiles[( row * columns ) + col] = RasterDataFactory.createRasterData( new RasterRect( 0, 0, tileWidth, tileHeight ), reader.getRasterDataInfo(), r, false, options ); } } this.sampleDomain = new RasterRect( 0, 0, reader.getWidth(), reader.getHeight() ); this.dataInfo = reader.getRasterDataInfo(); }
/** * Returns the min column, row and max column row of the given rect. The rectangle will be cut off to fit the data. * If the rect does not intersect the data, <code>null</code> will be returned. * * @param rect * @return {min column, min row, max column, max row} or <code>null</code> if the given rect does not intersect the * data. */ protected int[] getIntersectingTiles( RasterRect rect ) { RasterRect fRect = snapToGrid( rect ); if ( fRect != null ) { int minCol = getColNumber( fRect.x ); int minRow = getRowNumber( fRect.y ); int maxCol = getColNumber( fRect.x + fRect.width ); int maxRow = getRowNumber( fRect.y + fRect.height ); if ( ( maxCol != -1 ) && ( maxRow != -1 ) && ( minCol != infoFile.columns() ) && ( minRow != infoFile.rows() ) ) { return new int[] { minCol, minRow, maxCol, maxRow }; } } return null; }
/** * Read a raster from the grid file at location (row,column). * * @param columnId * * @param rowId * * @return the read raster or null if it could not be read. * @throws IOException */ public AbstractRaster getTile( int columnId, int rowId ) throws IOException { Envelope tileEnvelope = getTileEnvelope( columnId, rowId ); RasterGeoReference tileRasterReference = RasterGeoReference.create( OriginLocation.OUTER, tileEnvelope, infoFile.getTileRasterWidth(), infoFile.getTileRasterHeight() ); RasterRect tileRect = getGeoReference().createRelocatedReference( OriginLocation.OUTER ).convertEnvelopeToRasterCRS( tileEnvelope ); TileOffsetReader tReader = new TileOffsetReader( this, tileRect ); ByteBufferRasterData tileData = RasterDataFactory.createRasterData( infoFile.getTileRasterWidth(), infoFile.getTileRasterHeight(), getRasterDataInfo(), tReader, false ); SimpleRaster tile = new SimpleRaster( tileData, tileEnvelope, tileRasterReference, null ); return tile; }
@Override public void dispose() { originalReader.dispose(); } }
@Override public String getDataLocationId() { return originalReader.getDataLocationId(); }
@Override public int getHeight() { return originalReader.getHeight(); }
@Override public File file() { return originalReader.file(); }
@Override public RasterGeoReference getGeoReference() { return originalReader.getGeoReference(); }
/** * 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 ); } }