Class AbstractProductReader
- All Implemented Interfaces:
ProductReader
- Direct Known Subclasses:
AbstractProductBuilder,DimapProductReader,ImageProductReader
AbstractProductReader class can be used as a base class for new product reader implementations. The
only two methods which clients must implement are readProductNodes(Object, ProductSubsetDef) and
readBandRasterData(Band, int, int, int, int, ProductData, ProgressMonitor) methods.
To simplify implementation it is encouraged to implement readProductNodesImpl() and
readBandRasterDataImpl(...)
instead.
- Version:
- $Revision$ $Date$
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractProductReader(ProductReaderPlugIn readerPlugIn) Constructs a new abstract product reader. -
Method Summary
Modifier and TypeMethodDescriptionprotected static TiePointGridbuildTiePointGrid(String gridName, int gridWidth, int gridHeight, double offsetX, double offsetY, double subSamplingX, double subSamplingY, float[] tiePoints) protected static TiePointGridbuildTiePointGrid(String gridName, int gridWidth, int gridHeight, double offsetX, double offsetY, double subSamplingX, double subSamplingY, float[] tiePoints, int gridDiscontinutity) voidclose()Closes the access to all currently opened resources such as file input streams and all resources of this children directly owned by this reader.static voidconfigurePreferredTileSize(Product product) static PathconvertInputToPath(Object input) protected TiePointGridcreateTiePointGrid(String gridName, int gridWidth, int gridHeight, double offsetX, double offsetY, double subSamplingX, double subSamplingY, float[] tiePoints) Creates a tie point grid from the given properties.protected intgetGridDiscontinutity(String name) Used by thecreateTiePointGridmethod in order to determine the discontinuity mode for angle tie-point grids.getInput()Retrives the current output destination object.Retrieves a set of TreeNode objects that represent the physical product structure as stored on the harddrive.Returns the plug-in which created this product reader.Returns the subset information with which this data product is read from its physical source.protected booleanisInstanceOfValidInputType(Object input) Checks if the given object is an instance of one of the valid input types for this product reader.booleanChecks if this reader ignores metadata or not.booleanisNodeAccepted(String name) Tests whether or not a product node (a band, a tie-point grid or metadata element) with the given name is accepted with respect to the optional spectral band subset.booleanReturns if the reader fully supports the reading of subsets.voidreadBandRasterData(Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) Reads raster data from the data source specified by the given destination band into the given in-memory buffer and region.protected abstract voidreadBandRasterDataImpl(int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) The template method which is called by the method after an optional spatial subset has been applied to the input parameters.readGeoCoding(Product product) readProductNodes(Object input, ProductSubsetDef subsetDef) Reads the nodes of a data product and returns an in-memory representation of it.protected abstract ProductProvides an implementation of thereadProductNodesinterface method.protected voidprotected voidsetSubsetDef(ProductSubsetDef subsetDef) Sets the subset information.toString()Returns a string representation of the reader.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.esa.snap.core.dataio.ProductReader
readTiePointGridRasterData
-
Field Details
-
input
The input source
-
-
Constructor Details
-
AbstractProductReader
Constructs a new abstract product reader.- Parameters:
readerPlugIn- the reader plug-in which created this reader, can benullfor internal reader implementations
-
-
Method Details
-
getReaderPlugIn
Returns the plug-in which created this product reader.- Specified by:
getReaderPlugInin interfaceProductReader- Returns:
- the product reader plug-in, should never be
null
-
getInput
Retrives the current output destination object. The return value might benullif thesetInput()method has not been called so far.- Specified by:
getInputin interfaceProductReader
-
setInput
-
isMetadataIgnored
public boolean isMetadataIgnored()Checks if this reader ignores metadata or not.- Returns:
trueif so
-
getSubsetDef
Returns the subset information with which this data product is read from its physical source.- Specified by:
getSubsetDefin interfaceProductReader- Returns:
- the subset information, can be
null
-
setSubsetDef
Sets the subset information.- Parameters:
subsetDef- the subset definition
-
isNodeAccepted
Tests whether or not a product node (a band, a tie-point grid or metadata element) with the given name is accepted with respect to the optional spectral band subset. All accepted nodes will be part of the product read.- Parameters:
name- the node name- Returns:
trueif so
-
readProductNodes
Reads the nodes of a data product and returns an in-memory representation of it.The given subset info can be used to specify spatial and spectral portions of the original product. If the subset is omitted, the complete product is read in.
Whether the band data - the actual pixel values - is read in immediately or later when pixels are requested, is up to the implementation.
- Specified by:
readProductNodesin interfaceProductReader- Parameters:
input- an object representing a valid output for this product reader, might be aImageInputStreamor otherObjectto use for future decoding.subsetDef- a spectral or spatial subset (or both) of the product. Ifnull, the entire product is read in- Throws:
IllegalArgumentException- if input type is not supported (seeProductReaderPlugIn.getInputTypes()).IOException- if an I/O error occursIllegalFileFormatException- if the file format is unknown.
-
readProductNodesImpl
Provides an implementation of thereadProductNodesinterface method. Clients implementing this method can be sure that the input object and eventually the subset information has already been set.This method is called as a last step in the
readProductNodes(input, subsetInfo)method.- Returns:
- a new product instance
- Throws:
IOException- if an I/O error occurs
-
readGeoCoding
- Specified by:
readGeoCodingin interfaceProductReader- Returns:
- Throws:
IOException
-
readBandRasterData
public void readBandRasterData(Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException Reads raster data from the data source specified by the given destination band into the given in-memory buffer and region.For a complete description, please refer to the
ProductReader.readBandRasterData(Band, int, int, int, int, ProductData, com.bc.ceres.core.ProgressMonitor)interface definition} of this method.The
AbstractProductReaderimplements this method using the Template Method pattern. The template method in this case is the abstract method to which the call is delegated after an optional spatial subset given bygetSubsetDef()has been applied to the input parameters.- Specified by:
readBandRasterDatain interfaceProductReader- Parameters:
destBand- the destination band which identifies the data source from which to read the sample valuesdestOffsetX- the X-offset in the band's raster co-ordinatesdestOffsetY- the Y-offset in the band's raster co-ordinatesdestWidth- the width of region to be read given in the band's raster co-ordinatesdestHeight- the height of region to be read given in the band's raster co-ordinatesdestBuffer- the destination buffer which receives the sample values to be readpm- a monitor to inform the user about progress- Throws:
IOException- if an I/O error occursIllegalArgumentException- if the number of elements destination buffer not equalsdestWidth * destHeightor the destination region is out of the band's raster- See Also:
-
isSubsetReadingFullySupported
public boolean isSubsetReadingFullySupported()Returns if the reader fully supports the reading of subsets. Including sub-sampling in X- and Y-direction. This method is intended to be a hint to the SNAP framework. Depending on the return value the reading can be optimised.Implementations of this class should override this method in order to specify if subset reading is fully supported. The default implementation returns
false- Returns:
falseortrue, depending if subset reading is fully supported or not.
-
readBandRasterDataImpl
protected abstract void readBandRasterDataImpl(int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException The template method which is called by the method after an optional spatial subset has been applied to the input parameters.The destination band, buffer and region parameters are exactly the ones passed to the original call. Since the
destOffsetXanddestOffsetYparameters are already taken into account in thesourceOffsetXandsourceOffsetYparameters, an implementor of this method is free to ignore them.- Parameters:
sourceOffsetX- the absolute X-offset in source raster co-ordinatessourceOffsetY- the absolute Y-offset in source raster co-ordinatessourceWidth- the width of region providing samples to be read given in source raster co-ordinatessourceHeight- the height of region providing samples to be read given in source raster co-ordinatessourceStepX- the sub-sampling in X direction within the region providing samples to be readsourceStepY- the sub-sampling in Y direction within the region providing samples to be readdestBand- the destination band which identifies the data source from which to read the sample valuesdestOffsetX- the X-offset in the band's raster co-ordinatesdestOffsetY- the Y-offset in the band's raster co-ordinatesdestWidth- the width of region to be read given in the band's raster co-ordinatesdestHeight- the height of region to be read given in the band's raster co-ordinatesdestBuffer- the destination buffer which receives the sample values to be readpm- a monitor to inform the user about progress- Throws:
IOException- if an I/O error occurs- See Also:
-
close
Closes the access to all currently opened resources such as file input streams and all resources of this children directly owned by this reader. Its primary use is to allow the garbage collector to perform a vanilla job.This method should be called only if it is for sure that this object instance will never be used again. The results of referencing an instance of this class after a call to
close()are undefined.Overrides of this method should always call
super.close();after disposing this instance.- Specified by:
closein interfaceProductReader- Throws:
IOException- if an I/O error occurs
-
getProductComponents
Retrieves a set of TreeNode objects that represent the physical product structure as stored on the harddrive. The tree consists of: - a root node (the one returned) pointing to the directory that CONTAINS the product - any number of nested children that compose the product. Each TreeNod is configured as follows: - id: contains a string representation of the path. For the root node, this is the absolute path to the parent of the file returned by Product.getFileLocation(). For all subsequent nodes, the node name. - content: each node stores as content a java.io.File object that physically defines the node.The method returns null when a TreeNode can not be assembled (i.e. in-memory product, created from stream ...)
- Returns:
- the root TreeNode or null
-
isInstanceOfValidInputType
Checks if the given object is an instance of one of the valid input types for this product reader.- Parameters:
input- the input object passed toreadProductNodes(Object, ProductSubsetDef)- Returns:
trueif so- See Also:
-
getGridDiscontinutity
Used by thecreateTiePointGridmethod in order to determine the discontinuity mode for angle tie-point grids.The default implementation returns
TiePointGrid.DISCONT_AT_180for the names "lon", "long" or "longitude" ignoring letter case,TiePointGrid.DISCONT_NONEotherwise.- Parameters:
name- the grid name- Returns:
- the discontinuity mode, always one of
TiePointGrid.DISCONT_NONE,TiePointGrid.DISCONT_AT_180andTiePointGrid.DISCONT_AT_360.
-
createTiePointGrid
protected TiePointGrid createTiePointGrid(String gridName, int gridWidth, int gridHeight, double offsetX, double offsetY, double subSamplingX, double subSamplingY, float[] tiePoints) Creates a tie point grid from the given properties.The method uses the
getGridDiscontinutity(String)method in order to create an appropriate angular tie-point grids.- Parameters:
gridName- the grid namegridWidth- the grid's raster widthgridHeight- the grid's raster heightoffsetX- the grid origin's X-coordinate in pixel unitsoffsetY- the grid origin's Y-coordinate in pixel unitssubSamplingX- the grid X-subsampling in pixel unitssubSamplingY- the grid Y-subsampling in pixel unitstiePoints- the tie-points- Returns:
- the tie-point grid instance, never null
-
buildTiePointGrid
protected static TiePointGrid buildTiePointGrid(String gridName, int gridWidth, int gridHeight, double offsetX, double offsetY, double subSamplingX, double subSamplingY, float[] tiePoints) -
buildTiePointGrid
protected static TiePointGrid buildTiePointGrid(String gridName, int gridWidth, int gridHeight, double offsetX, double offsetY, double subSamplingX, double subSamplingY, float[] tiePoints, int gridDiscontinutity) -
configurePreferredTileSize
-
toString
Returns a string representation of the reader. -
convertInputToPath
-