Class RasterStore

All Implemented Interfaces:
AutoCloseable, ResourceOnFileSystem, StoreResource, DataSet, GridCoverageResource, Resource, Localized
Direct Known Subclasses:
AsciiGridStore, RawRasterStore

abstract class RasterStore extends PRJDataStore implements GridCoverageResource
Base class for the implementation of ASCII Grid or raw binary store. This base class manages the reading of following auxiliary files:
  • *.stx for statistics about bands.
  • *.clr for the image color map.
  • *.prj for the CRS definition.
Since:
1.2
Version:
1.2
  • Field Details

    • VISIBLE_BAND

      private static final int VISIBLE_BAND
      Band to make visible if an image contains many bands but a color map is defined for only one band.
      See Also:
    • NROWS

      static final String NROWS
      Keyword for the number of rows in the image.
      See Also:
    • NCOLS

      static final String NCOLS
      Keyword for the number of columns in the image.
      See Also:
    • STX

      static final String STX
      The filename extension of "*.stx" and "*.clr" files.
      See Also:
    • CLR

      static final String CLR
      The filename extension of "*.stx" and "*.clr" files.
      See Also:
    • colorModel

      private ColorModel colorModel
      The color model, created from the "*.clr" file content when first needed. The color model and sample dimensions are created together because they depend on the same properties.
    • sampleDimensions

      private List<SampleDimension> sampleDimensions
      The sample dimensions, created from the "*.stx" file content when first needed. The sample dimensions and color model are created together because they depend on the same properties. This list is unmodifiable.
      See Also:
    • nodataValue

      double nodataValue
      The value to replace by NaN values, or Double.NaN if none.
    • metadata

      org.opengis.metadata.Metadata metadata
      The metadata object, or null if not yet created.
    • RGB_BAND_NAMES

      private static final short[] RGB_BAND_NAMES
      Default names of bands when the color model is RGB or RGBA.
  • Constructor Details

    • RasterStore

      RasterStore(DataStoreProvider provider, StorageConnector connector) throws DataStoreException
      Creates a new raster store from the given file, URL or stream.
      Parameters:
      provider - the factory that created this DataStore instance, or null if unspecified.
      connector - information about the storage (file, URL, stream, etc).
      Throws:
      DataStoreException - if an error occurred while creating the data store for the given storage.
  • Method Details

    • getComponentFiles

      public Path[] getComponentFiles() throws DataStoreException
      Returns the URIDataStore.location as a Path component together with auxiliary files.
      Specified by:
      getComponentFiles in interface ResourceOnFileSystem
      Overrides:
      getComponentFiles in class PRJDataStore
      Returns:
      the main file and auxiliary files as paths, or an empty array if unknown.
      Throws:
      DataStoreException - if the URI cannot be converted to a Path.
    • createMetadata

      final void createMetadata(String formatName, String formatKey) throws DataStoreException
      Builds metadata and assigns the result to the metadata field.
      Parameters:
      formatName - name of the raster format.
      formatKey - key of format description in the SpatialMetadata database.
      Throws:
      DataStoreException - if an error occurred during the parsing process.
    • readColorMap

      private ColorModel readColorMap(int dataType, int mapSize, int numBands) throws DataStoreException, IOException
      Reads the "*.clr" auxiliary file. Syntax is as below, with one line per color:
      value red green blue
      The specification said that lines that do not start with a number shall be ignored as comment. Any characters after the fourth number shall also be ignored and can be used as comment.

      Limitations

      Current implementation requires the data type to be DataBuffer.TYPE_BYTE or DataBuffer.TYPE_SHORT. A future version could create scaled color model for floating point values as well.
      Parameters:
      mapSize - minimal size of index color model map. The actual size may be larger.
      numBands - number of bands in the sample model. Only one of them will be visible.
      Returns:
      the color model, or null if the file does not contain enough entries.
      Throws:
      NoSuchFileException - if the auxiliary file has not been found (when opened from path).
      FileNotFoundException - if the auxiliary file has not been found (when opened from URL).
      IOException - if another error occurred while opening the stream.
      NumberFormatException - if a number cannot be parsed.
      DataStoreException
    • readStatistics

      private Statistics[] readStatistics(String name, SampleModel sm) throws DataStoreException, IOException
      Reads the "*.stx" auxiliary file. Syntax is as below, with one line per band. Value between {…} are optional and can be skipped with a # sign in place of the number.
      band minimum maximum {mean} {std_deviation} {linear_stretch_min} {linear_stretch_max}
      The specification said that lines that do not start with a number shall be ignored as comment.
      Returns:
      statistics for each band. Some elements may be null if not specified in the file.
      Throws:
      NoSuchFileException - if the auxiliary file has not been found (when opened from path).
      FileNotFoundException - if the auxiliary file has not been found (when opened from URL).
      IOException - if another error occurred while opening the stream.
      NumberFormatException - if a number cannot be parsed.
      DataStoreException
    • loadBandDescriptions

      final void loadBandDescriptions(String name, SampleModel sm, Statistics... stats) throws DataStoreException
      Loads "*.stx" and "*.clr" files if present then builds sampleDimensions and colorModel from those information. If no color map is found, a grayscale color model is created.
      Parameters:
      name - name to use for the sample dimension, or null if untitled.
      sm - the sample model to use for creating a default color model if no "*.clr" file is found.
      stats - if the caller collected statistics by itself, those statistics for each band. Otherwise empty.
      Throws:
      DataStoreException - if an error occurred while loading an auxiliary file.
    • canNotReadAuxiliaryFile

      private void canNotReadAuxiliaryFile(String suffix, Exception exception)
      Sends a warning about a failure to read an optional auxiliary file. This is used for errors that affect only the rendering, not the georeferencing.
      Parameters:
      suffix - suffix of the auxiliary file.
      exception - error that occurred while reading the auxiliary file.
    • createCoverage

      final GridCoverage2D createCoverage(GridGeometry domain, RangeArgument range, WritableRaster data, Statistics stats)
      Creates the grid coverage resulting from a GridCoverageResource.read(GridGeometry, int...) operation.
      Parameters:
      domain - the effective domain after intersection and subsampling.
      range - indices of selected bands.
      data - the loaded data.
      stats - statistics to save as a property, or null if none.
      Returns:
      the grid coverage.
    • getSampleDimensions

      public List<SampleDimension> getSampleDimensions() throws DataStoreException
      Returns the sample dimensions computed by loadBandDescriptions(…). Shall be overridden by subclasses in a synchronized method. The subclass must ensure that loadBandDescriptions(…) has been invoked once.
      Specified by:
      getSampleDimensions in interface GridCoverageResource
      Returns:
      the sample dimensions, or null if not yet computed.
      Throws:
      DataStoreException - if an error occurred while reading definitions from the underlying data store.
      See Also:
    • close

      public void close() throws DataStoreException
      Closes this data store and releases any underlying resources. Shall be overridden by subclasses in a synchronized method.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in class DataStore
      Throws:
      DataStoreException - if an error occurred while closing this data store.
      See Also: