Class RawRasterStore

All Implemented Interfaces:
AutoCloseable, ResourceOnFileSystem, StoreResource, DataSet, GridCoverageResource, Resource, Localized

final class RawRasterStore extends RasterStore
Data store implementation for BIL, BIP, and BSQ raster files. Sample values are provided in a raw binary files, without compression. Information about image layout is provided in a separated text files.
Since:
1.2
Version:
1.3
  • Field Details

    • NBANDS

      private static final String NBANDS
      Keyword for the number of bands. Default value is 1.
      See Also:
    • NBITS

      private static final String NBITS
      Keyword for the number of bits per sample: 1, 4, 8, 16, 32. Default value is 8.
      See Also:
    • PIXELTYPE

      private static final String PIXELTYPE
      Keyword for the type of integers (signed or unsigned). Value can be SIGNEDINT for signed integers. Default value is unsigned integers.
      See Also:
    • BYTEORDER

      private static final String BYTEORDER
      Keyword for the byte order: I = Intel; M = Motorola. Default value is the byte order of host machine.
      See Also:
    • LAYOUT

      private static final String LAYOUT
      Keyword for the sample model: BIL, BIP or BSQ. Default value is RawRasterLayout.BIL.
      See Also:
    • SKIPBYTES

      private static final String SKIPBYTES
      Keyword for the offset in the stream of the first byte to read. Default value is 0.
      See Also:
    • BANDROWBYTES

      private static final String BANDROWBYTES
      Keyword for the number of bytes per band per row. This is used only with RawRasterLayout.BIL. Default value is (NCOLS x NBITS) / 8 rounded up.
      See Also:
    • TOTALROWBYTES

      private static final String TOTALROWBYTES
      Keyword for the total number of bytes in a row. Default value depends on the layout:
      See Also:
    • BANDGAPBYTES

      private static final String BANDGAPBYTES
      Number of bytes to skip between band. This is used only with RawRasterLayout.BSQ. Default value is 0.
      See Also:
    • ULXMAP

      private static final String ULXMAP
      Keyword for the x-axis coordinate of the center of the upper left pixel. Default value is 0.
      See Also:
    • ULYMAP

      private static final String ULYMAP
      Keyword for the y-axis coordinate of the center of the upper left pixel. Default value is NROWS - 1.
      See Also:
    • XDIM

      static final String XDIM
      Keyword for the pixel size in the x-axis dimension. Default value is 1.
      See Also:
    • YDIM

      static final String YDIM
      Keyword for the pixel size in the y-axis dimension. Default value is 1.
      See Also:
    • NODATA

      private static final String NODATA
      Keyword for the value to replace by NaN. This is not documented in the ESRI specification but used in practice.
      See Also:
    • CELL_ANCHOR

      private static final org.opengis.referencing.datum.PixelInCell CELL_ANCHOR
      The "cell center" versus "cell corner" interpretation of translation coefficients. The ESRI specification said that the coefficients map to pixel center.
    • input

      private ChannelDataInput input
      The object to use for reading data, or null if the channel has been closed.
    • reader

      private RawRasterReader reader
      Helper method for reading a rectangular region from the input stream. This is created when the header is parsed, because its depends on the type of data. A non-null value is used as a sentinel value meaning that the header has been read.
  • Constructor Details

    • RawRasterStore

      RawRasterStore(RawRasterStoreProvider provider, StorageConnector connector) throws DataStoreException
      Creates a new raw raster store from the given file or URL.
      Parameters:
      provider - the factory that created this DataStore instance, or null if unspecified.
      connector - information about the storage (file, URL, etc).
      Throws:
      DataStoreException - if an error occurred while closing unused streams.
  • 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 RasterStore
      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.
    • getMetadata

      public org.opengis.metadata.Metadata getMetadata() throws DataStoreException
      Returns the metadata associated to the raw binary file.
      Specified by:
      getMetadata in interface Resource
      Specified by:
      getMetadata in class DataStore
      Returns:
      the metadata associated to the raw binary.
      Throws:
      DataStoreException - if an error occurred during the parsing process.
      See Also:
    • getGridGeometry

      public GridGeometry getGridGeometry() throws DataStoreException
      Returns the valid extent of grid coordinates together with the conversion from those grid coordinates to real world coordinates.
      Returns:
      extent of grid coordinates together with their mapping to "real world" coordinates.
      Throws:
      DataStoreException - if an error occurred while reading definitions from the underlying data store.
      See Also:
    • getSampleDimensions

      public List<SampleDimension> getSampleDimensions() throws DataStoreException
      Returns the ranges of sample values.
      Specified by:
      getSampleDimensions in interface GridCoverageResource
      Overrides:
      getSampleDimensions in class RasterStore
      Returns:
      ranges of sample values.
      Throws:
      DataStoreException - if an error occurred while reading definitions from the underlying data store.
      See Also:
    • errors

      private Errors errors()
      Returns localized resources for warnings an error messages.
    • missingProperty

      private DataStoreContentException missingProperty(PRJDataStore.AuxiliaryContent header, String keyword)
      Returns the exception to throw for a missing property in the header file.
      Parameters:
      header - the header to parse.
      keyword - the missing keyword.
      Returns:
      the exception to throw.
    • ignoredProperty

      private void ignoredProperty(String keyword, int value)
      Sends a warning if a property was specified in the header file but has been ignored by this data store.
      Parameters:
      keyword - keyword of the potentially ignored property.
      value - the specified value, or 0 if it is the default value.
    • indexOf

      private int indexOf(String keyword, String value, String... alternatives)
      Returns the index of value in the alternatives array, or -1 if not found. The comparison ignore cases. If the value is not found in the array, a warning message is emitted.
      Parameters:
      keyword - the keyword (used in case a warning message is emitted).
      value - the value to search.
      alternatives - valid values.
      Returns:
      index of value in the alternatives array, or -1 if not found.
    • parseStrictlyPositive

      private int parseStrictlyPositive(String keyword, String value) throws DataStoreContentException
      Parses the given string as a strictly positive integer.
      Parameters:
      keyword - the keyword (used in case a warning message is emitted).
      value - the value to parse as an unsigned integer.
      Returns:
      the parsed value, guaranteed greater than zero.
      Throws:
      DataStoreContentException
    • readHeader

      private void readHeader() throws IOException, DataStoreException
      Reads the "*.hdr" and "*.prj" files. After a successful return, reader is guaranteed non-null.

      Note: we don't do this initialization in the constructor for giving a chance for users to register listeners first.

      Throws:
      IOException - if the auxiliary file cannot be found or read.
      DataStoreException - if the auxiliary file cannot be parsed.
      RasterFormatException - if the number of bits or the signed/unsigned property is invalid.
      ArithmeticException - if image size of pixel/line/band stride is too large.
      IllegalArgumentException - if SampleModel constructor rejects some argument values.
    • read

      public GridCoverage read(GridGeometry domain, int... ranges) throws DataStoreException
      Loads the data.
      Parameters:
      domain - desired grid extent and resolution, or null for reading the whole domain.
      ranges - indices of bands to load.
      Returns:
      the grid coverage for the specified domain.
      Throws:
      DataStoreException - if an error occurred while reading the grid coverage data.
    • canNotRead

      private String canNotRead()
      Returns an error message saying that the file cannot be read.
    • close

      public void close() throws DataStoreException
      Closes this data store and releases any underlying resources.
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class RasterStore
      Throws:
      DataStoreException - if an error occurred while closing this data store.
      See Also: