org.geotools.coverage.grid.io
Class AbstractGridCoverage2DReader

Object
  extended by AbstractGridCoverage2DReader
All Implemented Interfaces:
GridCoverageReader
Direct Known Subclasses:
ArcGridReader, ArcSDERasterGridCoverage2DReader, GeoTiffReader, GTopo30Reader, ImageMosaicReader, ImagePyramidReader, WorldImageReader

public abstract class AbstractGridCoverage2DReader
extends Object
implements GridCoverageReader

This class is a first attempt for providing a way to get more informations out of a single 2D raster datasets (x,y). It is worth to remark that for the moment this is thought for 2D rasters not for 3D or 4D rasters (x,y,z,t).

The main drawback I see with the current GeoApi GridCoverageReader interface is that there is no way to get real information about a raster source unless you instantiate a GridCoverage. As an instance it is impossible to know the envelope, the number of overviews, the tile size. This information is needed in order to perform decimation on reading or to use built-in overviews
This really impacts the ability to exploit raster datasets in a desktop environment where caching is crucial.

Since:
2.3
Author:
Simone Giannecchini

Field Summary
protected  boolean closeMe
          Temp variable used in many readers.
protected static GridCoverageFactory coverageFactory
          Caches a default GridCoverageFactory for usage in plugins.
protected  String coverageName
          Coverage name
protected  CoordinateReferenceSystem crs
          crs for this coverage
protected static Color[] demColors
          Default color ramp.
protected static double EPS
           
protected  boolean gzipped
          In case we are trying to read from a GZipped file this will be set to true.
protected  double[] highestRes
          Highest resolution availaible for this reader.
protected  Hints hints
          Hints used by the AbstractGridCoverage2DReader subclasses.
protected  ImageInputStream inStream
          Input stream that can be used to initialize subclasses of AbstractGridCoverage2DReader.
protected  int numOverviews
          This contains the maximum number of grid coverages in the file/stream.
protected static CoordinateOperationFactory operationFactory
          Buffered factory for coordinate operations.
protected  GeneralEnvelope originalEnvelope
          Envelope read from file
protected  GeneralGridRange originalGridRange
          The original GridRange for the GridCoverage2D of this reader.
protected  double[][] overViewResolutions
          Resolutions avialaible through an overviews based mechanism.
protected  MathTransform raster2Model
          2DGridToWorld math transform.
protected  Object source
          Source to read from
 
Constructor Summary
AbstractGridCoverage2DReader()
           
 
Method Summary
protected  GridCoverage createImageCoverage(PlanarImage image)
          Creates a GridCoverage for the provided PlanarImage using the originalEnvelope that was provided for this coverage.
protected  GridCoverage createImageCoverage(PlanarImage image, MathTransform raster2Model)
          Creates a GridCoverage for the provided PlanarImage using the raster2Model that was provided for this coverage.
protected  void decimationOnReadingControl(Integer imageChoice, ImageReadParam readP, double[] requestedRes)
          This method is responsible for evaluating possible subsampling factors once the best resolution level has been found, in case we have support for overviews, or starting from the original coverage in case there are no overviews availaible.
 void dispose()
          Disposes this reader.
 CoordinateReferenceSystem getCrs()
          Retrieves the CoordinateReferenceSystem for dataset pointed by this AbstractGridCoverage2DReader.
 String getCurrentSubname()
           
 int getGridCoverageCount()
           
 String[] getMetadataNames()
           
 String getMetadataValue(String name)
           
 GeneralEnvelope getOriginalEnvelope()
          Retrieves the GeneralEnvelope for this AbstractGridCoverage2DReader.
 GeneralGridRange getOriginalGridRange()
          Retrieves the GeneralGridRange that represents the raster grid dimensions of the highest resolution level in this dataset.
protected  double[] getResolution(GeneralEnvelope envelope, Rectangle2D dim, CoordinateReferenceSystem crs)
          This method is responsible for computing the resolutions in for the provided grid geometry in the provided crs.
 Object getSource()
          Retrieves the source for this AbstractGridCoverage2DReader.
 boolean hasMoreGridCoverages()
           
protected  boolean isScaleTranslate(MathTransform transform)
          Checks the transformation is a pure scale/translate instance (using a tolerance)
 String[] listSubNames()
           
protected  Integer setReadParams(ImageReadParam readP, GeneralEnvelope requestedEnvelope, Rectangle requestedDim)
          This method is responsible for preparing the read param for doing an ImageReader.read(int, ImageReadParam).
 void skip()
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface GridCoverageReader
getFormat, read
 

Field Detail

coverageFactory

protected static final GridCoverageFactory coverageFactory
Caches a default GridCoverageFactory for usage in plugins.


EPS

protected static final double EPS
See Also:
Constant Field Values

operationFactory

protected static final CoordinateOperationFactory operationFactory
Buffered factory for coordinate operations.


demColors

protected static final Color[] demColors
Default color ramp. Preset colors used to generate an Image from the raw data


numOverviews

protected volatile int numOverviews
This contains the maximum number of grid coverages in the file/stream. Until multi-image files are supported, this is going to be 0 or 1.


raster2Model

protected MathTransform raster2Model
2DGridToWorld math transform.


crs

protected CoordinateReferenceSystem crs
crs for this coverage


originalEnvelope

protected GeneralEnvelope originalEnvelope
Envelope read from file


coverageName

protected String coverageName
Coverage name


source

protected Object source
Source to read from


hints

protected Hints hints
Hints used by the AbstractGridCoverage2DReader subclasses.


highestRes

protected double[] highestRes
Highest resolution availaible for this reader.


closeMe

protected boolean closeMe
Temp variable used in many readers.


gzipped

protected boolean gzipped
In case we are trying to read from a GZipped file this will be set to true.


originalGridRange

protected GeneralGridRange originalGridRange
The original GridRange for the GridCoverage2D of this reader.


inStream

protected ImageInputStream inStream
Input stream that can be used to initialize subclasses of AbstractGridCoverage2DReader.


overViewResolutions

protected double[][] overViewResolutions
Resolutions avialaible through an overviews based mechanism.

Constructor Detail

AbstractGridCoverage2DReader

public AbstractGridCoverage2DReader()
Method Detail

setReadParams

protected Integer setReadParams(ImageReadParam readP,
                                GeneralEnvelope requestedEnvelope,
                                Rectangle requestedDim)
                         throws IOException,
                                TransformException
This method is responsible for preparing the read param for doing an ImageReader.read(int, ImageReadParam).

This method is responsible for preparing the read param for doing an ImageReader.read(int, ImageReadParam). It sets the passed ImageReadParam in terms of decimation on reading using the provided requestedEnvelope and requestedDim to evaluate the needed resolution. It also returns and Integer representing the index of the raster to be read when dealing with multipage raster.

Parameters:
readP - an instance of ImageReadParam for setting the subsampling factors.
requestedEnvelope - the GeneralEnvelope we are requesting.
requestedDim - the requested dimensions.
Returns:
the index of the raster to read in the underlying data source.
Throws:
IOException
TransformException

isScaleTranslate

protected final boolean isScaleTranslate(MathTransform transform)
Checks the transformation is a pure scale/translate instance (using a tolerance)

Parameters:
transform -
Returns:

decimationOnReadingControl

protected final void decimationOnReadingControl(Integer imageChoice,
                                                ImageReadParam readP,
                                                double[] requestedRes)
This method is responsible for evaluating possible subsampling factors once the best resolution level has been found, in case we have support for overviews, or starting from the original coverage in case there are no overviews availaible. Anyhow this methof should not be called directly but subclasses should make use of the setReadParams method instead in order to transparently look for overviews.

Parameters:
imageChoice -
readP -
requestedRes -

createImageCoverage

protected final GridCoverage createImageCoverage(PlanarImage image)
                                          throws IOException
Creates a GridCoverage for the provided PlanarImage using the originalEnvelope that was provided for this coverage.

Parameters:
image - contains the data for the coverage to create.
Returns:
a GridCoverage
Throws:
IOException

createImageCoverage

protected final GridCoverage createImageCoverage(PlanarImage image,
                                                 MathTransform raster2Model)
                                          throws IOException
Creates a GridCoverage for the provided PlanarImage using the raster2Model that was provided for this coverage.

This method is vital when working with coverages that have a raster to model transformation that is not a simple scale and translate.

Parameters:
image - contains the data for the coverage to create.
raster2Model - is the MathTransform that maps from the raster space to the model space.
Returns:
a GridCoverage
Throws:
IOException

getResolution

protected final double[] getResolution(GeneralEnvelope envelope,
                                       Rectangle2D dim,
                                       CoordinateReferenceSystem crs)
                                throws DataSourceException
This method is responsible for computing the resolutions in for the provided grid geometry in the provided crs.

It is worth to note that the returned resolution array is of length of 2 and it always is lon, lat for the moment.
It might be worth to remove the axes reordering code when we are confident enough with the code to handle the north-up crs.

TODO use orthodromic distance?

Parameters:
envelope - the GeneralEnvelope
dim -
crs -
Throws:
DataSourceException

getCrs

public final CoordinateReferenceSystem getCrs()
Retrieves the CoordinateReferenceSystem for dataset pointed by this AbstractGridCoverage2DReader.

Returns:
the CoordinateReferenceSystem for dataset pointed by this AbstractGridCoverage2DReader.

getOriginalGridRange

public final GeneralGridRange getOriginalGridRange()
Retrieves the GeneralGridRange that represents the raster grid dimensions of the highest resolution level in this dataset.

Returns:
the GeneralGridRange that represents the raster grid dimensions of the highest resolution level in this dataset.

getOriginalEnvelope

public final GeneralEnvelope getOriginalEnvelope()
Retrieves the GeneralEnvelope for this AbstractGridCoverage2DReader.

Returns:
the GeneralEnvelope for this AbstractGridCoverage2DReader.

getSource

public final Object getSource()
Retrieves the source for this AbstractGridCoverage2DReader.

Specified by:
getSource in interface GridCoverageReader
Returns:
the source for this AbstractGridCoverage2DReader.

dispose

public void dispose()
Disposes this reader.

This method just tries to close the underlying ImageInputStream.

Specified by:
dispose in interface GridCoverageReader

skip

public void skip()
Specified by:
skip in interface GridCoverageReader
See Also:
GridCoverageReader.skip()

hasMoreGridCoverages

public boolean hasMoreGridCoverages()
Specified by:
hasMoreGridCoverages in interface GridCoverageReader
See Also:
GridCoverageReader.hasMoreGridCoverages()

listSubNames

public String[] listSubNames()
Specified by:
listSubNames in interface GridCoverageReader
See Also:
GridCoverageReader.listSubNames()

getCurrentSubname

public String getCurrentSubname()
Specified by:
getCurrentSubname in interface GridCoverageReader
See Also:
GridCoverageReader.getCurrentSubname()

getMetadataNames

public String[] getMetadataNames()
Specified by:
getMetadataNames in interface GridCoverageReader
See Also:
GridCoverageReader.getMetadataNames()

getMetadataValue

public String getMetadataValue(String name)
                        throws MetadataNameNotFoundException
Specified by:
getMetadataValue in interface GridCoverageReader
Throws:
MetadataNameNotFoundException
See Also:
GridCoverageReader.getMetadataValue(java.lang.String)

getGridCoverageCount

public int getGridCoverageCount()
See Also:
org.opengis.coverage.grid.GridCoverageReader#getGridCoverageCount()


Copyright © 1996-2008 Geotools. All Rights Reserved.