/** * @return the number of grid columns */ public int getTileColumns() { return infoFile.columns(); }
/** * Calculates the id for a tile at a given position in the grid. * * @param columnId * column id, must be in the range [0 ... #columns - 1] * @param rowId * row id, must be in the range [0 ... #rows - 1] * @return the tile's id */ protected int getTileId( int columnId, int rowId ) { return rowId * infoFile.columns() + columnId; }
/** * @param rasterCoord * in raster coordinates normally x. * @return the column number of tile which holds the given raster coordinate. */ private int getColNumber( float rasterCoord ) { int column = (int) Math.floor( rasterCoord / infoFile.getTileRasterWidth() ); if ( column < 0 ) { column = -1; } if ( column >= infoFile.columns() ) { column = infoFile.columns(); } return column; }
/** * 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 ); } }
for ( int columnId = 0; columnId < infoFile.columns(); ++columnId ) { SimpleRaster rasterTile = (SimpleRaster) getTile( rowId, columnId ); if ( rasterTile != null ) {
/** * 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; }
/** * Instantiates this grid reader with the given information. * * @param infoFile */ protected synchronized void instantiate( GridMetaInfoFile infoFile ) { this.infoFile = infoFile; this.envelope = infoFile.getEnvelope( OriginLocation.OUTER ); this.rasterRect = new RasterRect( 0, 0, infoFile.columns() * infoFile.getTileRasterWidth(), infoFile.rows() * infoFile.getTileRasterHeight() ); this.rasterDataInfo = infoFile.getDataInfo(); // this.envelopeWidth = envelope.getMax().get0() - envelope.getMin().get0(); // this.envelopeHeight = envelope.getMax().get1() - envelope.getMin().get1(); // this.envelopeWidth = envelope.getSpan0(); // this.envelopeHeight = envelope.getSpan1(); // this.rows = infoFile.rows(); // this.columns = infoFile.columns(); // this.tileSamplesX = infoFile.getTileSamplesX(); // this.tileSamplesY = infoFile.getTileSamplesY(); // this.tileWidth = envelope.getSpan0() / infoFile.columns(); // this.tileHeight = envelope.getSpan1() / infoFile.rows(); this.tilesPerBlob = infoFile.columns() * infoFile.rows(); this.sampleSize = ( rasterDataInfo.getDataType().getSize() * rasterDataInfo.bands() ); this.bytesPerTile = infoFile.getTileRasterWidth() * infoFile.getTileRasterHeight() * sampleSize; }
/** * @param gMif * @param width * @param height */ private CacheInfoFile( GridMetaInfoFile gMif, int width, int height, boolean[][] tilesOnFile, long modificationTime ) { super( gMif.getGeoReference(), gMif.rows(), gMif.columns(), gMif.getTileRasterWidth(), gMif.getTileRasterHeight(), gMif.getDataInfo() ); this.rWidth = width; this.rHeight = height; this.tilesOnFile = tilesOnFile; this.modificationTime = modificationTime; this.envelope = gMif.getGeoReference().getEnvelope( OriginLocation.OUTER, rWidth, rHeight, envelope.getCoordinateSystem() ); }
/** * Creates a new {@link GriddedTileContainer} instances. * * @param infoFile * containing the relevant information. * */ protected GriddedTileContainer( GridMetaInfoFile infoFile ) { this.rdi = infoFile.getDataInfo(); this.envelope = infoFile.getEnvelope( OriginLocation.OUTER ); this.envelopeWidth = envelope.getMax().get0() - envelope.getMin().get0(); this.envelopeHeight = envelope.getMax().get1() - envelope.getMin().get1(); // this.envelopeWidth = envelope.getSpan0(); // this.envelopeHeight = envelope.getSpan1(); this.rows = infoFile.rows(); this.columns = infoFile.columns(); this.tileSamplesX = infoFile.getTileRasterWidth(); this.tileSamplesY = infoFile.getTileRasterHeight(); this.tileWidth = envelopeWidth / columns; this.tileHeight = envelopeHeight / rows; this.rasterReference = infoFile.getGeoReference(); LOG.debug( "envelope: " + envelope ); LOG.debug( "raster reference: " + rasterReference ); SampleResolution sr = new SampleResolution( new double[] { rasterReference.getResolutionX(), rasterReference.getResolutionY() } ); this.resolutionInfo = new ResolutionInfo( sr ); }