org.deegree.coverage.raster.io.grid
Class GridReader

java.lang.Object
  extended by org.deegree.coverage.raster.io.grid.GridReader
All Implemented Interfaces:
RasterReader
Direct Known Subclasses:
GridFileReader

public abstract class GridReader
extends Object
implements RasterReader

The GridReader class TODO add class documentation here.

Version:
$Revision: 31644 $, $Date: 2011-08-24 22:27:43 +0200 (Wed, 24 Aug 2011) $
Author:
Rutger Bezema, last edited by: $Author: mschneider $

Field Summary
protected  GridMetaInfoFile infoFile
          Holds information on the grid.
protected  int sampleSize
          The size of one sample
 
Constructor Summary
GridReader()
           
 
Method Summary
protected  ByteBuffer allocateTileBuffer(boolean direct, boolean forCache)
          Allocate a buffer which can hold a tile.
 boolean canReadTiles()
          should return true if the given reader can easily read tiles,without consuming much more memory than needed.
 long getBytesPerTile()
           
 Envelope getEnvelope()
           
 RasterGeoReference getGeoReference()
           
 int getHeight()
           
protected  int[] getIntersectingTiles(RasterRect rect)
          Returns the min column, row and max column row of the given rect.
 int getNumberOfTiles()
           
 RasterDataInfo getRasterDataInfo()
           
 AbstractRaster getTile(int columnId, int rowId)
          Read a raster from the grid file at location (row,column).
 int getTileColumns()
           
 ByteBuffer getTileData(int column, int row, ByteBuffer buffer)
           
protected  Envelope getTileEnvelope(int column, int row)
          Calculates the envelope for a tile at a given position in the grid.
protected  int getTileId(int columnId, int rowId)
          Calculates the id for a tile at a given position in the grid.
 int getTileRasterHeight()
           
 int getTileRasterWidth()
           
 int getTileRows()
           
 int getTilesPerBlob()
           
 int getWidth()
           
protected  void instantiate(GridMetaInfoFile infoFile)
          Instantiates this grid reader with the given information.
 AbstractRaster load(InputStream stream, RasterIOOptions options)
          Read the given input stream into an abstract raster.
protected abstract  void read(int columnId, int rowId, ByteBuffer buffer)
          Reads the data from the grid.
 void setTilesPerBlob(int tilesPerBlob)
           
 boolean shouldCreateCacheFile()
           
protected  RasterRect snapToGrid(RasterRect original)
          Get intersection of the requested rectangle with the rectangle of the grid file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.deegree.coverage.raster.io.RasterReader
canLoad, dispose, file, getDataLocationId, getSupportedFormats, load, read
 

Field Detail

infoFile

protected GridMetaInfoFile infoFile
Holds information on the grid.


sampleSize

protected int sampleSize
The size of one sample

Constructor Detail

GridReader

public GridReader()
Method Detail

instantiate

protected void instantiate(GridMetaInfoFile infoFile)
Instantiates this grid reader with the given information.

Parameters:
infoFile -

snapToGrid

protected RasterRect snapToGrid(RasterRect original)
Get intersection of the requested rectangle with the rectangle of the grid file.

Parameters:
original -
Returns:
the intersection with the grids raster rectangle and the given.

getTileId

protected int getTileId(int columnId,
                        int rowId)
Calculates the id for a tile at a given position in the grid.

Parameters:
columnId - column id, must be in the range [0 ... #columns - 1]
rowId - row id, must be in the range [0 ... #rows - 1]
Returns:
the tile's id

getTileEnvelope

protected Envelope getTileEnvelope(int column,
                                   int row)
Calculates the envelope for a tile at a given position in the grid.

Parameters:
column - column id, must be in the range [0 ... #columns - 1]
row - row id, must be in the range [0 ... #rows - 1]
Returns:
the tile's envelope

getTile

public AbstractRaster getTile(int columnId,
                              int rowId)
                       throws IOException
Read a raster from the grid file at location (row,column).

Parameters:
columnId -
rowId -
Returns:
the read raster or null if it could not be read.
Throws:
IOException

read

protected abstract void read(int columnId,
                             int rowId,
                             ByteBuffer buffer)
                      throws IOException
Reads the data from the grid.

Parameters:
columnId -
rowId -
buffer -
Throws:
IOException

load

public AbstractRaster load(InputStream stream,
                           RasterIOOptions options)
                    throws IOException
Description copied from interface: RasterReader
Read the given input stream into an abstract raster.

Specified by:
load in interface RasterReader
Returns:
the loaded raster
Throws:
IOException - may be thrown when there is a problem with reading the raster.

getNumberOfTiles

public int getNumberOfTiles()
Returns:
the number of tiles in this blob.

getBytesPerTile

public long getBytesPerTile()
Returns:
the number of bytes one tile in the given grid has.

getGeoReference

public RasterGeoReference getGeoReference()
Specified by:
getGeoReference in interface RasterReader
Returns:
the geo reference of the read raster

getHeight

public int getHeight()
Specified by:
getHeight in interface RasterReader
Returns:
the height (in pixels) of the read raster

getWidth

public int getWidth()
Specified by:
getWidth in interface RasterReader
Returns:
the width (in pixels) of the read raster

getTileRasterWidth

public int getTileRasterWidth()
Returns:
the width of a tile in raster coordinates.

getTileRasterHeight

public int getTileRasterHeight()
Returns:
the height of a tile in raster coordinates.

canReadTiles

public boolean canReadTiles()
Description copied from interface: RasterReader
should return true if the given reader can easily read tiles,without consuming much more memory than needed.

Specified by:
canReadTiles in interface RasterReader
Returns:
true if the reader can easily read tiles.

getIntersectingTiles

protected int[] getIntersectingTiles(RasterRect rect)
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, null will be returned.

Parameters:
rect -
Returns:
{min column, min row, max column, max row} or null if the given rect does not intersect the data.

shouldCreateCacheFile

public boolean shouldCreateCacheFile()
Specified by:
shouldCreateCacheFile in interface RasterReader
Returns:
true if a cache file should be created for the read raster.

getTileData

public ByteBuffer getTileData(int column,
                              int row,
                              ByteBuffer buffer)
                       throws IOException
Parameters:
column -
row -
buffer -
Returns:
a newly allocated buffer if the given one was null
Throws:
IOException

allocateTileBuffer

protected ByteBuffer allocateTileBuffer(boolean direct,
                                        boolean forCache)
Allocate a buffer which can hold a tile.

Parameters:
direct - if the buffer should be direct
forCache - if the buffer is used for caching mechanisms.
Returns:
a ByteBuffer which can hold a tile.

getTileRows

public int getTileRows()
Returns:
the number of grid rows

getTileColumns

public int getTileColumns()
Returns:
the number of grid columns

getTilesPerBlob

public int getTilesPerBlob()
Returns:
the tilesPerBlob

setTilesPerBlob

public void setTilesPerBlob(int tilesPerBlob)
Parameters:
tilesPerBlob -

getRasterDataInfo

public RasterDataInfo getRasterDataInfo()
Specified by:
getRasterDataInfo in interface RasterReader
Returns:
the raster data info

getEnvelope

public final Envelope getEnvelope()
Returns:
the envelope


Copyright © 2011. All Rights Reserved.