Class AbstractProductReader

    • Constructor Detail

      • AbstractProductReader

        protected AbstractProductReader​(ProductReaderPlugIn readerPlugIn)
        Constructs a new abstract product reader.
        Parameters:
        readerPlugIn - the reader plug-in which created this reader, can be null for internal reader implementations
    • Method Detail

      • getReaderPlugIn

        public ProductReaderPlugIn getReaderPlugIn()
        Returns the plug-in which created this product reader.
        Specified by:
        getReaderPlugIn in interface ProductReader
        Returns:
        the product reader plug-in, should never be null
      • getInput

        public Object getInput()
        Retrives the current output destination object. The return value might be null if the setInput() method has not been called so far.
        Specified by:
        getInput in interface ProductReader
      • setInput

        protected void setInput​(Object input)
      • isMetadataIgnored

        public boolean isMetadataIgnored()
        Checks if this reader ignores metadata or not.
        Returns:
        true if so
      • getSubsetDef

        public ProductSubsetDef getSubsetDef()
        Returns the subset information with which this data product is read from its physical source.
        Specified by:
        getSubsetDef in interface ProductReader
        Returns:
        the subset information, can be null
      • setSubsetDef

        protected void setSubsetDef​(ProductSubsetDef subsetDef)
        Sets the subset information.
        Parameters:
        subsetDef - the subset definition
      • isNodeAccepted

        public boolean isNodeAccepted​(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. All accepted nodes will be part of the product read.
        Parameters:
        name - the node name
        Returns:
        true if so
      • readProductNodes

        public Product readProductNodes​(Object input,
                                        ProductSubsetDef subsetDef)
                                 throws IOException
        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:
        readProductNodes in interface ProductReader
        Parameters:
        input - an object representing a valid output for this product reader, might be a ImageInputStream or other Object to use for future decoding.
        subsetDef - a spectral or spatial subset (or both) of the product. If null, the entire product is read in
        Throws:
        IllegalArgumentException - if input type is not supported (see ProductReaderPlugIn.getInputTypes()).
        IOException - if an I/O error occurs
        IllegalFileFormatException - if the file format is unknown.
      • readProductNodesImpl

        protected abstract Product readProductNodesImpl()
                                                 throws IOException
        Provides an implementation of the readProductNodes interface 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
      • 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:
        false or true, 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 destOffsetX and destOffsetY parameters are already taken into account in the sourceOffsetX and sourceOffsetY parameters, an implementor of this method is free to ignore them.

        Parameters:
        sourceOffsetX - the absolute X-offset in source raster co-ordinates
        sourceOffsetY - the absolute Y-offset in source raster co-ordinates
        sourceWidth - the width of region providing samples to be read given in source raster co-ordinates
        sourceHeight - the height of region providing samples to be read given in source raster co-ordinates
        sourceStepX - the sub-sampling in X direction within the region providing samples to be read
        sourceStepY - the sub-sampling in Y direction within the region providing samples to be read
        destBand - the destination band which identifies the data source from which to read the sample values
        destOffsetX - the X-offset in the band's raster co-ordinates
        destOffsetY - the Y-offset in the band's raster co-ordinates
        destWidth - the width of region to be read given in the band's raster co-ordinates
        destHeight - the height of region to be read given in the band's raster co-ordinates
        destBuffer - the destination buffer which receives the sample values to be read
        pm - a monitor to inform the user about progress
        Throws:
        IOException - if an I/O error occurs
        See Also:
        readBandRasterData(org.esa.snap.core.datamodel.Band, int, int, int, int, org.esa.snap.core.datamodel.ProductData, com.bc.ceres.core.ProgressMonitor), getSubsetDef()
      • close

        public void close()
                   throws IOException
        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:
        close in interface ProductReader
        Throws:
        IOException - if an I/O error occurs
      • getProductComponents

        public TreeNode<File> 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
      • 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 name
        gridWidth - the grid's raster width
        gridHeight - the grid's raster height
        offsetX - the grid origin's X-coordinate in pixel units
        offsetY - the grid origin's Y-coordinate in pixel units
        subSamplingX - the grid X-subsampling in pixel units
        subSamplingY - the grid Y-subsampling in pixel units
        tiePoints - 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

        public static void configurePreferredTileSize​(Product product)
      • toString

        public String toString()
        Returns a string representation of the reader.
        Overrides:
        toString in class Object
        Returns:
        a string representation of the object.
      • convertInputToPath

        public static Path convertInputToPath​(Object input)