org.geotoolkit.coverage.sql
Class LayerCoverageReader

Object
  extended by GridCoverageStore
      extended by GridCoverageReader
          extended by LayerCoverageReader
All Implemented Interfaces:
Localized, LogProducer

public class LayerCoverageReader
extends GridCoverageReader

A grid coverage reader for a layer. This class provides a way to read the data using only the GridCoverageReader API, with input of kind Layer.

The read method actually reads two-dimensional slices selected according the spatio-temporal envelope given to the GridCoverageReadParam argument.

Usage example:

CoverageDatabase      db     = new CoverageDatabase(...);
LayerCoverageReader   reader = db.createGridCoverageReader("My layer");
GridCoverageReadParam param  = new GridCoverageGridParam();
param.setEnvelope(...);
param.setResolution(...);
GridCoverage coverage = reader.read(0, param);

Since:
3.10
Version:
3.20
Author:
Martin Desruisseaux (Geomatys)
See Also:
CoverageDatabase.createGridCoverageReader(String), CoverageDatabase.readSlice(CoverageQuery), GridCoverageReference.read(CoverageEnvelope, IIOListeners)
Module:
coverage/geotk-coverage-sql (download)    View source code for this class

Field Summary
protected  CoverageDatabase database
          The coverage database which created this LayerCoverageReader.
protected  CoverageEnvelope temporaryEnvelope
          A temporary object used for computing the value to be given to the Layer.getCoverageReference(CoverageEnvelope) method.
 
Fields inherited from class GridCoverageStore
abortRequested
 
Constructor Summary
protected LayerCoverageReader(CoverageDatabase database)
          Creates a new reader for the given database.
 
Method Summary
 void dispose()
          Allows any resources held by this reader to be released.
 SpatialMetadata getCoverageMetadata(int index)
          Returns the metadata associated with the given coverage.
 List<LocalName> getCoverageNames()
          Returns the layer name.
 GeneralGridGeometry getGridGeometry(int index)
          Returns the most commonly used grid geometry.
 Layer getInput()
          Returns the current layer which is used as input, or null if none.
 List<GridSampleDimension> getSampleDimensions(int index)
          Returns the most commonly used sample dimensions for each band of the GridCoverage to be read.
 SpatialMetadata getStreamMetadata()
          Returns the metadata associated with the stream as a whole.
 GridCoverage read(int index, GridCoverageReadParam param)
          Reads the data and return them as a coverage.
 GridCoverage2D readSlice(int index, GridCoverageReadParam param)
          Reads the data of a two-dimensional slice and returns them as a coverage.
 void reset()
          Restores the GridCoverageReader to its initial state.
 void setInput(Object input)
          Sets a new layer as input.
 
Methods inherited from class GridCoverageReader
getMetadata, getProperties, getSampleValueRanges
 
Methods inherited from class GridCoverageStore
abort, getLocale, getLogLevel, setLocale, setLogLevel
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

database

protected final CoverageDatabase database
The coverage database which created this LayerCoverageReader.


temporaryEnvelope

protected final CoverageEnvelope temporaryEnvelope
A temporary object used for computing the value to be given to the Layer.getCoverageReference(CoverageEnvelope) method. Subclasses can use this field for computation purpose, but its content shall not be presumed stable.

Constructor Detail

LayerCoverageReader

protected LayerCoverageReader(CoverageDatabase database)
Creates a new reader for the given database. The setInput(Object) method must be invoked before this reader can be used.

Parameters:
database - The database to used with this reader.
Method Detail

getInput

public final Layer getInput()
                     throws CoverageStoreException
Returns the current layer which is used as input, or null if none.

Overrides:
getInput in class GridCoverageReader
Returns:
The current input, or null if none.
Throws:
CoverageStoreException - If the operation failed.
See Also:
ImageReader.getInput()

setInput

public void setInput(Object input)
              throws CoverageStoreException
Sets a new layer as input. The given input can be either a Layer instance, or the name of a layer as a CharSequence.

Overrides:
setInput in class GridCoverageReader
Parameters:
input - The new input as a Layer instance or a CharSequence, or null for removing any input previously set.
Throws:
IllegalArgumentException - If the given input is not of a legal type.
CoverageStoreException - If the operation failed.
See Also:
ImageReader.setInput(Object)

getCoverageNames

public List<LocalName> getCoverageNames()
                                 throws CoverageStoreException
Returns the layer name.

Specified by:
getCoverageNames in class GridCoverageReader
Returns:
The names of the coverages.
Throws:
CoverageStoreException - If an error occurs while reading the information from the input source.
See Also:
ImageReader.getNumImages(boolean)

getGridGeometry

public GeneralGridGeometry getGridGeometry(int index)
                                    throws CoverageStoreException
Returns the most commonly used grid geometry. If no grid geometry can be found (for example because the layer doesn't contain any coverage), then this method returns null.

Specified by:
getGridGeometry in class GridCoverageReader
Parameters:
index - The index of the coverage to be queried.
Returns:
The grid geometry for the GridCoverage at the specified index.
Throws:
CoverageStoreException - If an error occurs while reading the information from the input source.
See Also:
ImageReader.getWidth(int), ImageReader.getHeight(int)

getSampleDimensions

public List<GridSampleDimension> getSampleDimensions(int index)
                                              throws CoverageStoreException
Returns the most commonly used sample dimensions for each band of the GridCoverage to be read. If sample dimensions are not known, then this method returns null.

Specified by:
getSampleDimensions in class GridCoverageReader
Parameters:
index - The index of the coverage to be queried.
Returns:
The list of sample dimensions for the GridCoverage at the specified index, or null if none. This list length is equals to the number of bands in the GridCoverage.
Throws:
CoverageStoreException - If an error occurs while reading the information from the input source.

getStreamMetadata

public SpatialMetadata getStreamMetadata()
                                  throws CoverageStoreException
Returns the metadata associated with the stream as a whole. This method fetches the metadata from the database only; it does not attempt to read the image file.

Overrides:
getStreamMetadata in class GridCoverageReader
Returns:
The metadata associated with the input source as a whole, or null.
Throws:
CoverageStoreException - If an error occurs while reading the information from the input source.
Since:
3.16
See Also:
ImageReader.getStreamMetadata()

getCoverageMetadata

public SpatialMetadata getCoverageMetadata(int index)
                                    throws CoverageStoreException
Returns the metadata associated with the given coverage. This method fetches the metadata from the database only; it does not attempt to read the image file.

Overrides:
getCoverageMetadata in class GridCoverageReader
Parameters:
index - The index of the coverage to be queried.
Returns:
The metadata associated with the given coverage, or null.
Throws:
CoverageStoreException - If an error occurs while reading the information from the input source.
Since:
3.16
See Also:
ImageReader.getImageMetadata(int)

read

public GridCoverage read(int index,
                         GridCoverageReadParam param)
                  throws CoverageStoreException
Reads the data and return them as a coverage. The current implementation delegates to readSlice(int, GridCoverageReadParam). A future implementation may return a three-dimensional coverage.

Specified by:
read in class GridCoverageReader
Parameters:
index - The image index (usually 0).
param - Optional read parameters (including the envelope and resolution to request), or null if none.
Returns:
The coverage, or null if none.
Throws:
CoverageStoreException - If an error occurred while querying the database or reading the image.
See Also:
ImageReader.read(int)

readSlice

public GridCoverage2D readSlice(int index,
                                GridCoverageReadParam param)
                         throws CoverageStoreException
Reads the data of a two-dimensional slice and returns them as a coverage. Note that the returned two-dimensional slice is not guaranteed to have exactly the requested envelope. Callers may need to check the geometry of the returned envelope and perform an additional resampling if needed.

Parameters:
index - The image index (usually 0).
param - Optional read parameters (including the envelope and resolution to request), or null if none.
Returns:
The coverage, or null if none.
Throws:
CoverageStoreException - If an error occurred while querying the database or reading the image.
See Also:
CoverageDatabase.readSlice(CoverageQuery)

reset

public void reset()
           throws CoverageStoreException
Restores the GridCoverageReader to its initial state.

Overrides:
reset in class GridCoverageReader
Throws:
CoverageStoreException - If an error occurs while restoring to the initial state.
See Also:
ImageReader.reset()

dispose

public void dispose()
             throws CoverageStoreException
Allows any resources held by this reader to be released. The result of calling any other method subsequent to a call to this method is undefined.

Overrides:
dispose in class GridCoverageReader
Throws:
CoverageStoreException - If an error occurs while disposing resources.
See Also:
ImageReader.dispose()


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.