Class AbstractGridCoverage2DReader

    • Field Detail

      • EPS

        protected static double EPS
        Small number used for double comparisons
      • numOverviews

        protected int numOverviews
        This contains the number of overviews.aaa
      • raster2Model

        protected MathTransform raster2Model
        2DGridToWorld math transform.
      • originalEnvelope

        protected GeneralBounds originalEnvelope
        Envelope read from file
      • coverageName

        protected String coverageName
        Coverage name
      • source

        protected Object source
        Source to read from
      • highestRes

        protected double[] highestRes
        Highest resolution available 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.
      • overViewResolutions

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

        protected Double[] scales
        scales and offsets for rescaling
      • offsets

        protected Double[] offsets
      • inStreamSPI

        protected ImageInputStreamSpi inStreamSPI
      • dtLayout

        protected DatasetLayout dtLayout
        Coverage DatasetLayout containing information about Overviews and Mask management
    • Constructor Detail

      • AbstractGridCoverage2DReader

        protected AbstractGridCoverage2DReader()
        Default protected constructor. Useful for wrappers.
      • AbstractGridCoverage2DReader

        public AbstractGridCoverage2DReader​(Object input)
                                     throws DataSourceException
        Creates a new instance of a AIGReader. I assume nothing about file extension.
        Parameters:
        input - Source object for which we want to build an AIGReader.
        Throws:
        DataSourceException
      • AbstractGridCoverage2DReader

        public AbstractGridCoverage2DReader​(Object input,
                                            Hints hints)
                                     throws DataSourceException
        Creates a new instance of a AIGReader. I assume nothing about file extension.
        Parameters:
        input - Source object for which we want to build an AIGReader.
        hints - Hints to be used by this reader throughout his life.
        Throws:
        DataSourceException
    • Method Detail

      • checkName

        protected boolean checkName​(String coverageName)
        This method is responsible for checking the provided coverage name against the coverage name for this GridCoverage2DReader.
        Parameters:
        coverageName - the coverage name to check.
        Returns:
        true if this GridCoverage2DReader contains the provided coverage name, false otherwise.
      • read

        public abstract GridCoverage2D read​(GeneralParameterValue[] parameters)
                                     throws IllegalArgumentException,
                                            IOException
        Read the current grid coverage from the stream.

        Example:

         
         
         
        Specified by:
        read in interface GridCoverage2DReader
        Specified by:
        read in interface GridCoverageReader
        Parameters:
        parameters - Optional parameters matching Format.getReadParameters().
        Returns:
        a grid coverage from the input source.
        Throws:
        InvalidParameterNameException - if a parameter in parameters doesn't have a recognized name.
        InvalidParameterValueException - if a parameter in parameters doesn't have a valid value.
        ParameterNotFoundException - if a parameter was required for the operation but was not provided in the parameters list.
        CannotCreateGridCoverageException - if the coverage can't be created for a logical reason (for example an unsupported format, or an inconsistency found in the data).
        IOException - if a read operation failed for some other input/output reason, including FileNotFoundException if no file with the given name can be found, or IIOException if an error was thrown by the underlying image library.
        InvalidParameterNameException - if a parameter in parameters doesn't have a recognized name.
        InvalidParameterValueException - if a parameter in parameters doesn't have a valid value.
        ParameterNotFoundException - if a parameter was required for the operation but was not provided in the parameters list.
        IllegalArgumentException
      • setReadParams

        protected Integer setReadParams​(OverviewPolicy overviewPolicy,
                                        ImageReadParam readP,
                                        GeneralBounds 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:
        overviewPolicy - it can be one of Hints#VALUE_OVERVIEW_POLICY_IGNORE, Hints#VALUE_OVERVIEW_POLICY_NEAREST, Hints#VALUE_OVERVIEW_POLICY_QUALITY or Hints#VALUE_OVERVIEW_POLICY_SPEED. It specifies the policy to compute the overviews level upon request.
        readP - an instance of ImageReadParam for setting the subsampling factors.
        requestedEnvelope - the GeneralBounds we are requesting.
        requestedDim - the requested dimensions.
        Returns:
        the index of the raster to read in the underlying data source.
        Throws:
        IOException
        TransformException
      • setReadParams

        protected Integer setReadParams​(String coverageName,
                                        OverviewPolicy overviewPolicy,
                                        ImageReadParam readP,
                                        GeneralBounds 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:
        overviewPolicy - it can be one of Hints#VALUE_OVERVIEW_POLICY_IGNORE, Hints#VALUE_OVERVIEW_POLICY_NEAREST, Hints#VALUE_OVERVIEW_POLICY_QUALITY or Hints#VALUE_OVERVIEW_POLICY_SPEED. It specifies the policy to compute the overviews level upon request.
        readP - an instance of ImageReadParam for setting the subsampling factors.
        requestedEnvelope - the GeneralBounds we are requesting.
        requestedDim - the requested dimensions.
        Returns:
        the index of the raster to read in the underlying data source.
        Throws:
        IOException
        TransformException
      • getReadingResolutions

        public double[] getReadingResolutions​(OverviewPolicy policy,
                                              double[] requestedResolution)
                                       throws IOException
        Returns the actual resolution used to read the data given the specified target resolution and the specified overview policy
        Specified by:
        getReadingResolutions in interface GridCoverage2DReader
        Parameters:
        policy - the OverviewPolicy to use during evaluation.
        requestedResolution - the requested resolution
        Returns:
        an array of 2 double with the resolution of the selected overview.
        Throws:
        IOException - in case an error occurs.
      • getReadingResolutions

        public double[] getReadingResolutions​(String coverageName,
                                              OverviewPolicy policy,
                                              double[] requestedResolution)
                                       throws IOException
        Returns the actual resolution used to read the data given the specified target resolution and the specified overview policy
        Specified by:
        getReadingResolutions in interface GridCoverage2DReader
        Parameters:
        coverageName - the name of the coverage to work on.
        policy - the OverviewPolicy to use during evaluation.
        requestedResolution - the requested resolution
        Returns:
        an array of 2 double with the resolution of the selected overview.
        Throws:
        IOException - in case an error occurs.
      • decimationOnReadingControl

        protected final void decimationOnReadingControl​(String coverageName,
                                                        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 available.

        Anyhow this method should not be called directly but subclasses should make use of the setReadParams method instead in order to transparently look for overviews.

      • 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​(String coverageName,
                                                         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 GridCoverage2D 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
      • createImageCoverage

        protected final GridCoverage2D createImageCoverage​(String coverageName,
                                                           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 static final double[] getResolution​(GeneralBounds 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
        Throws:
        DataSourceException
      • getOriginalGridRange

        public GridEnvelope getOriginalGridRange​(String coverageName)
        Retrieves the GeneralGridEnvelope that represents the raster grid dimensions of the highest resolution level in this dataset.
        Specified by:
        getOriginalGridRange in interface GridCoverage2DReader
        Parameters:
        coverageName - the name of the coverage to work with
        Returns:
        the GeneralGridEnvelope that represents the raster grid dimensions of the highest resolution level in this dataset.
      • dispose

        public void dispose()
        Disposes this reader.

        This method just tries to close the underlying ImageInputStream.

        Specified by:
        dispose in interface GridCoverageReader
      • getGridCoverageNames

        public String[] getGridCoverageNames()
        Description copied from interface: GridCoverageReader
        Retrieve the list of coverages contained within the input source. Each grid can have a different coordinate system, number of dimensions and grid geometry. For example, a HDF-EOS file (GRID.HDF) contains 6 grid coverages each having a different projection. An empty array will be returned if no sub names exist.
        Specified by:
        getGridCoverageNames in interface GridCoverageReader
        Returns:
        The list of grid coverages contained within the input source.
      • getMetadataNames

        public String[] getMetadataNames​(String coverageName)
        Description copied from interface: GridCoverageReader
        Returns the list of metadata keywords associated with a specific gridCoverage referred by name. If no metadata is available, the array will be empty.
        Specified by:
        getMetadataNames in interface GridCoverageReader
        Returns:
        The list of metadata keywords for the input source.
      • getMetadataValue

        public String getMetadataValue​(String coverageName,
                                       String name)
        Description copied from interface: GridCoverageReader
        Retrieve the metadata value for a given metadata name for a specified coverage.
        Specified by:
        getMetadataValue in interface GridCoverageReader
        name - Metadata keyword for which to retrieve metadata.
        Returns:
        The metadata value for the given metadata name. Should be one of the name returned by GridCoverageReader.getMetadataNames().
      • getInfo

        public ServiceInfo getInfo()
        Information about this source.

        Subclasses should provide additional format specific information.

        Specified by:
        getInfo in interface GridCoverage2DReader
        Returns:
        ServiceInfo describing getSource().
      • getFiles

        protected List<FileGroupProvider.FileGroup> getFiles()
                                                      throws IOException
        Returns a list of files making up the source data for this reader (as a whole). The default implementation returns the source, if it can be made into a File object, or null otherwise.
        Throws:
        IOException
      • getSourceAsFile

        protected File getSourceAsFile()
        Returns the source as a File, if it can be converted to one, and it exists
      • getInfo

        public ResourceInfo getInfo​(String coverageName)
        Default implementation returns a FileResourceInfo containing same fileGroup list contained in the ServiceInfo object.
        Specified by:
        getInfo in interface GridCoverage2DReader
        Returns:
        ResourceInfo describing a specific coverage.
      • finalize

        protected void finalize()
                         throws Throwable
        Forcing disposal of this AbstractGridCoverage2DReader which may keep an ImageInputStream open.
        Overrides:
        finalize in class Object
        Throws:
        Throwable
      • getDynamicParameters

        public Set<ParameterDescriptor<List>> getDynamicParameters()
                                                            throws IOException
        Return the set of dynamic parameterDescriptors (the ones related to domains) for this reader. Default implementation returns an empty set of parameters
        Specified by:
        getDynamicParameters in interface GridCoverage2DReader
        Returns:
        the Set of dynamic read parameters supported by this GridCoverage2DReader.
        Throws:
        IOException - in case an error occurs while creating the Set of dynamic parameters.
      • getDynamicParameters

        public Set<ParameterDescriptor<List>> getDynamicParameters​(String coverageName)
                                                            throws IOException
        Return the set of dynamic parameterDescriptors (the ones related to domains) for this reader. Default implementation returns an empty set of parameters
        Specified by:
        getDynamicParameters in interface GridCoverage2DReader
        Parameters:
        coverageName - the name of the coverage to work with
        Returns:
        the Set of dynamic read parameters supported by this GridCoverage2DReader.
        Throws:
        IOException - in case an error occurs while creating the Set of dynamic parameters.
      • getDatasetLayout

        public DatasetLayout getDatasetLayout()
        Description copied from interface: GridCoverage2DReader
        Returns the DatasetLayout for the coverage.
        Specified by:
        getDatasetLayout in interface GridCoverage2DReader
        Returns:
        a DatasetLayout object containing info about Overview number and Image masks.
      • getDatasetLayout

        public DatasetLayout getDatasetLayout​(String coverageName)
        Description copied from interface: GridCoverage2DReader
        Returns the DatasetLayout for the specified coverage.
        Specified by:
        getDatasetLayout in interface GridCoverage2DReader
        Parameters:
        coverageName - the name of the coverage for which we do want to get the DatasetLayout
        Returns:
        a DatasetLayout object containing info about Overview number and Image masks.
      • getOverviewGridEnvelope

        public GridEnvelope getOverviewGridEnvelope​(int overviewIndex)
                                             throws IOException
        Throws:
        IOException
      • getOverviewGridEnvelope

        public GridEnvelope getOverviewGridEnvelope​(String coverageName,
                                                    int overviewIndex)
                                             throws IOException
        Throws:
        IOException
      • getImageLayout

        public ImageLayout getImageLayout​(String coverageName)
                                   throws IOException
        Description copied from interface: GridCoverage2DReader
        Retrieve the ImageLayout for the specified coverage.

        Throw an IllegalArgumentException in case the name is wrong and/or no such a coverage exists.

        Specified by:
        getImageLayout in interface GridCoverage2DReader
        Parameters:
        coverageName - the name of the coverage for which we want to know the GridEnvelope.
        Returns:
        an ImageLayout that is useful for actually knowing the ColorModel, the SampleModel as well as the tile grid for a certain coverage.
        Throws:
        IOException
      • getImageLayout

        public ImageLayout getImageLayout()
                                   throws IOException
        Description copied from interface: GridCoverage2DReader
        Retrieve the ImageLayout for the default coverage.

        Throw an IllegalArgumentException in case the name is wrong and/or no such a coverage exists.

        Specified by:
        getImageLayout in interface GridCoverage2DReader
        Returns:
        an ImageLayout that is useful for actually knowing the ColorModel, the SampleModel as well as the tile grid for the default coverage.
        Throws:
        IOException
      • setLayout

        protected void setLayout​(ImageReader reader)
                          throws IOException
        Extract the ImageLayout from the provided reader for the first available image.
        Parameters:
        reader - an istance of ImageReader
        Throws:
        IOException - in case an error occurs
      • setlayout

        protected void setlayout​(ImageLayout layout)
        Set the provided layout for this GridCoverage2DReader-
        Parameters:
        layout - the ImageLayout to set. It must be nont null
      • getResolutionLevels

        public double[][] getResolutionLevels()
                                       throws IOException
        Description copied from interface: GridCoverage2DReader
        Retrieve the resolution levels for the default coverage.

        Throw an IllegalArgumentException in case the name is wrong and/or no such a coverage exists.

        Specified by:
        getResolutionLevels in interface GridCoverage2DReader
        Returns:
        the resolution levels for the default coverage.
        Throws:
        IOException
      • getResolutionLevels

        public double[][] getResolutionLevels​(String coverageName)
                                       throws IOException
        Description copied from interface: GridCoverage2DReader
        Retrieve the resolution levels for the specified coverage.

        Throw an IllegalArgumentException in case the name is wrong and/or no such a coverage exists.

        Specified by:
        getResolutionLevels in interface GridCoverage2DReader
        Parameters:
        coverageName - the name of the coverage for which we want to know the resolution levels.
        Returns:
        the resolution levels for the specified coverage.
        Throws:
        IOException
      • getHighestRes

        protected double[] getHighestRes​(String coverageName)
      • getHighestRes

        protected double[] getHighestRes()
      • getGroundControlPoints

        public GroundControlPoints getGroundControlPoints()
        Return the ground control points for the default coverage, or null if there are none
      • getGroundControlPoints

        public GroundControlPoints getGroundControlPoints​(String coverageName)
        Return the ground control points for the specified, or null if there are none
      • getRescaledRasterToModel

        protected AffineTransform getRescaledRasterToModel​(RenderedImage coverageRaster)
        Computes the raster to model of a rescaled output raster, based on the original transform and output raster scaling factor
      • getSibling

        protected static File getSibling​(File file,
                                         String extension)
        Retrieves the sibling of the specified file, if available, or null otherwise
      • addAllSiblings

        protected void addAllSiblings​(File file,
                                      List<File> files,
                                      String... extensions)
        Adds all the siblings that could be found to exist to the given file list
      • addSiblings

        protected void addSiblings​(List<File> files,
                                   File... siblings)
        Adds the specified siblings, if not null, and existing
      • getMultiLevelROIProvider

        protected MultiLevelROIProvider getMultiLevelROIProvider​(String coverageName)
      • collectScaleOffset

        protected void collectScaleOffset​(IIOMetadata iioMetadata)
        Collects the scales and offsets for value rescaling from the metadata, if present
      • getPamDataset

        public static PAMDataset getPamDataset​(File sourceFile,
                                               IIOMetadata metadata)
        Method that looks for an external PAMDataset first, and if not found, checks for an internal GDALMetadata inside a custom tag.

        The method is tolerant to invalid metadata contents and will log at INFO level in case of invalid metadata structure: there might be files with invalid metadata that used to be read just fine before PAM dataset reading was implemented.

      • getPamDataset

        public static PAMDataset getPamDataset​(TIFFImageMetadata metadata)
        If available, parses the GDAL_METADATA tag contents and transforms it into a PAMDataset