Class GeoTiffStore

java.lang.Object
org.apache.sis.storage.DataStore
org.apache.sis.storage.geotiff.GeoTiffStore
All Implemented Interfaces:
AutoCloseable, Aggregate, Resource, Localized

public class GeoTiffStore extends DataStore implements Aggregate
A data store backed by GeoTIFF files.
Since:
0.8
Version:
1.3
  • Field Details

    • encoding

      final Charset encoding
      The encoding of strings in the metadata. The TIFF specification said that is shall be US-ASCII, but Apache SIS nevertheless let the user specifies an alternative encoding if needed.
    • reader

      private Reader reader
      The GeoTIFF reader implementation, or null if the store has been closed.
      See Also:
    • location

      private final URI location
      The DataStoreProvider.LOCATION parameter value, or null if none. This is used for information purpose only, not for actual reading operations.
      See Also:
    • path

      final Path path
      Same value than location but as a path, or null if none. Stored separately because conversion from path to URI back to path is not looseness (relative paths become absolutes).
    • namespace

      private org.opengis.util.NameSpace namespace
      The data store identifier created from the filename, or null if none. Defined as a namespace for use as the scope of children resources (the images). This is created when first needed.
      Design note: we do not create this field in the constructor because its creation invokes the user-overrideable #customize(int, GenericName) method.
      See Also:
    • isNamespaceSet

      private boolean isNamespaceSet
      Whether namespace has been determined. Note that the resulting namespace may still be null.
      See Also:
    • metadata

      private org.opengis.metadata.Metadata metadata
      The metadata, or null if not yet created.
      See Also:
    • nativeMetadata

      private TreeTable nativeMetadata
      The native metadata, or null if not yet created.
      See Also:
    • components

      private List<GridCoverageResource> components
      Description of images in this GeoTIFF files. This collection is created only when first needed.
      See Also:
    • hidden

      final boolean hidden
      Whether this GeotiffStore will be hidden. If true, then some metadata that would normally be provided in this GeoTiffStore will be provided by individual components instead.
    • customizer

      final SchemaModifier customizer
      The user-specified method for customizing the band definitions. Never null.
  • Constructor Details

    • GeoTiffStore

      public GeoTiffStore(GeoTiffStoreProvider provider, StorageConnector connector) throws DataStoreException
      Creates a new GeoTIFF store from the given file, URL or stream object. This constructor invokes StorageConnector.closeAllExcept(Object), keeping open only the needed resource.
      Parameters:
      provider - the factory that created this DataStore instance, or null if unspecified.
      connector - information about the storage (URL, stream, etc).
      Throws:
      DataStoreException - if an error occurred while opening the GeoTIFF file.
    • GeoTiffStore

      public GeoTiffStore(DataStore parent, DataStoreProvider provider, StorageConnector connector, boolean hidden) throws DataStoreException
      Creates a new GeoTIFF store as a component of a larger data store.
      Example: A Landsat data set is a collection of files in a directory or ZIP file, which includes more than 10 GeoTIFF files (one image per band or product for a scene). LandsatStore is a data store opening the Landsat metadata file as the main file, then opening each band/product using a GeoTIFF data store. Those bands/products are components of the Landsat data store.
      If the hidden parameter is true, some metadata that would normally be provided in this GeoTiffStore will be provided by individual components instead.
      Parameters:
      parent - the parent that contains this new GeoTIFF store component, or null if none.
      provider - the factory that created this DataStore instance, or null if unspecified.
      connector - information about the storage (URL, stream, etc).
      hidden - true if this GeoTIFF store will not be directly accessible from the parent. It is the case if the parent store will expose only some components instead of the GeoTIFF store itself.
      Throws:
      DataStoreException - if an error occurred while opening the GeoTIFF file.
      Since:
      1.1
  • Method Details

    • namespace

      final org.opengis.util.NameSpace namespace()
      Returns the namespace to use in identifier of components, or null if none. This method must be invoked inside a block synchronized on this.
    • listeners

      final StoreListeners listeners()
      Opens access to listeners for ImageFileDirectory.
      See Also:
    • getOpenParameters

      public Optional<org.opengis.parameter.ParameterValueGroup> getOpenParameters()
      Returns the parameters used to open this GeoTIFF data store. The parameters are described by GeoTiffStoreProvider.getOpenParameters() and contains at least a parameter named "location" with a URI value. The return value may be empty if the storage input cannot be described by a URI (for example a GeoTIFF file reading directly from a ReadableByteChannel).
      Specified by:
      getOpenParameters in class DataStore
      Returns:
      parameters used for opening this data store.
      See Also:
    • getIdentifier

      public Optional<org.opengis.util.GenericName> getIdentifier() throws DataStoreException
      Returns an identifier constructed from the name of the TIFF file. An identifier is available only if the storage input specified at construction time was something convertible to URI, for example an URL, File or Path.
      Specified by:
      getIdentifier in interface Resource
      Overrides:
      getIdentifier in class DataStore
      Returns:
      the identifier derived from the filename.
      Throws:
      DataStoreException - if an error occurred while fetching the identifier.
      Since:
      1.0
      See Also:
    • setFormatInfo

      final void setFormatInfo(MetadataBuilder builder)
      Sets the metadata/identificationInfo/resourceFormat node to "GeoTIFF" format.
    • getMetadata

      public org.opengis.metadata.Metadata getMetadata() throws DataStoreException
      Returns information about the dataset as a whole. The returned metadata object can contain information such as the spatiotemporal extent of the dataset, contact information about the creator or distributor, data quality, usage constraints and more.
      Specified by:
      getMetadata in interface Resource
      Specified by:
      getMetadata in class DataStore
      Returns:
      information about the dataset.
      Throws:
      DataStoreException - if an error occurred while reading the data.
      See Also:
    • getNativeMetadata

      public Optional<TreeTable> getNativeMetadata() throws DataStoreException
      Returns TIFF tags and GeoTIFF keys as a tree for debugging purpose. The tags and keys appear in the order they are declared in the file. The columns are tag numerical code as an Integer, tag name as a String and value as an Object.

      This method should not be invoked during normal operations; the standard metadata are preferred because they allow abstraction of data format details. Native metadata should be used only when an information does not appear in standard metadata, or for debugging purposes.

      Performance note

      Since this method should not be invoked in normal operations, it has not been tuned for performance. Invoking this method may cause a lot of seek operations.
      Overrides:
      getNativeMetadata in class DataStore
      Returns:
      resources information structured in an implementation-specific way.
      Throws:
      DataStoreException - if an error occurred while reading the metadata.
      Since:
      1.2
    • errorIO

      final DataStoreException errorIO(IOException e)
      Returns the exception to throw when an I/O error occurred. This method wraps the exception with a "Cannot read <filename>" message.
    • reader

      private Reader reader() throws DataStoreException
      Returns the reader if it is not closed, or thrown an exception otherwise.
      Throws:
      DataStoreException
      See Also:
    • components

      public List<GridCoverageResource> components() throws DataStoreException
      Returns descriptions of all images in this GeoTIFF file. Images are not immediately loaded.

      If an error occurs during iteration in the returned collection, an unchecked BackingStoreException will be thrown with a DataStoreException as its cause.

      Specified by:
      components in interface Aggregate
      Returns:
      descriptions of all images in this GeoTIFF file.
      Throws:
      DataStoreException - if an error occurred while fetching the image descriptions.
      Since:
      1.0
    • findResource

      public GridCoverageResource findResource(String sequence) throws DataStoreException
      Returns the image at the given index. Images numbering starts at 1. If the given string has a scope (e.g. "filename:1"), then the scope
      Overrides:
      findResource in class DataStore
      Parameters:
      sequence - string representation of the image index, starting at 1.
      Returns:
      image at the given index.
      Throws:
      DataStoreException - if the requested image cannot be obtained.
      See Also:
    • parseImageIndex

      private int parseImageIndex(String sequence) throws IllegalNameException
      Validates input resource name and extracts the image index it should contain. The resource name may be of the form "1" or "filename:1". We verify that:
      • Input tip (last name part) is a parsable integer.
      • If input provides more than a tip, all test before the tip matches this datastore namespace (should be the name of the Geotiff file without its extension).
      Parameters:
      sequence - a string representing the name of a resource present in this datastore.
      Returns:
      the index of the Geotiff image matching the requested resource. There is no verification that the returned index is valid.
      Throws:
      IllegalNameException - if the argument use an invalid namespace or if the tip is not an integer.
    • addListener

      public <T extends StoreEvent> void addListener(Class<T> eventType, StoreListener<? super T> listener)
      Registers a listener to notify when the specified kind of event occurs in this data store. The current implementation of this data store can emit only WarningEvents; any listener specified for another kind of events will be ignored.
      Specified by:
      addListener in interface Resource
      Overrides:
      addListener in class DataStore
      Type Parameters:
      T - compile-time value of the eventType argument.
      Parameters:
      eventType - type of StoreEvent to listen (cannot be null).
      listener - listener to notify about events.
    • close

      public void close() throws DataStoreException
      Closes this GeoTIFF store and releases any underlying resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in class DataStore
      Throws:
      DataStoreException - if an error occurred while closing the GeoTIFF file.
      See Also:
    • errors

      final Errors errors()
      Returns the error resources in the current locale.
    • warning

      final void warning(LogRecord record)
      Reports a warning contained in the given LogRecord. Note that the given record will not necessarily be sent to the logging framework; if the user has registered at least one listener, then the record will be sent to the listeners instead.

      This method sets the source class name and source method name to hard-coded values. Those values assume that the warnings occurred indirectly from a call to getMetadata() in this class. We do not report private classes or methods as the source of warnings.

      Parameters:
      record - the warning to report.
      See Also: