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

final class Store extends URIDataStore implements FeatureSet
A data store which creates feature instances from a CSV file using the OGC Moving Features specification. See package javadoc for more information on the syntax.
Since:
0.7
Version:
1.2
  • Field Details

    • COMMENT

      private static final char COMMENT
      The character at the beginning of lines to ignore in the header. Note that this is not part of OGC Moving Feature Specification.
      See Also:
    • METADATA

      static final char METADATA
      The character at the beginning of metadata lines.
      See Also:
    • QUOTE

      private static final char QUOTE
      The quote character. Quotes inside quoted texts must be doubled.
      See Also:
    • SEPARATOR

      static final char SEPARATOR
      The column separator.
      See Also:
    • ORDINATE_SEPARATOR

      static final char ORDINATE_SEPARATOR
      The separator between coordinate values in a coordinate tuple.
      See Also:
    • TYPE_PREFIX

      private static final String TYPE_PREFIX
      The prefix for elements in the @columns line that specify the data type, as required by the OGC CSV encoding specification. Examples: xsd:boolean, xsd:decimal, xsd:integer, etc.

      Note that this prefix is slightly different than the "xs:" prefix used in https://www.w3.org/2009/XMLSchema/XMLSchema.xsd file. This data store implementation accepts both.

      See Also:
    • XS_PREFIX

      private static final String XS_PREFIX
      The prefix used in https://www.w3.org/2009/XMLSchema/XMLSchema.xsd file. This is not the same prefix than the one specified by OGC CSV encoding, but this implementation accepts both.
      See Also:
    • source

      private BufferedReader source
      The reader, set by the constructor and cleared when no longer needed.
      See Also:
    • encoding

      private final Charset encoding
      The character encoding, or null if unspecified (in which case the platform default is assumed). Note that the default value is different than the moving feature specification, which requires UTF-8. See "Departures from Moving Features specification" in package javadoc.
    • metadata

      private transient DefaultMetadata metadata
      The metadata object, or null if not yet created.
    • envelope

      private final ImmutableEnvelope envelope
      The three- or four-dimensional envelope together with the CRS. This envelope contains a vertical component if the feature trajectories are 3D, and a temporal component if the CSV file contains a start time and end time.
      See Also:
    • featureType

      final DefaultFeatureType featureType
      Description of the columns found in the CSV file.
      See Also:
    • hasTrajectories

      private boolean hasTrajectories
      true if featureType contains a trajectory column. This field should be considered immutable after Store construction.
      See Also:
    • spatialDimensionCount

      private short spatialDimensionCount
      The number of dimensions other than time in the coordinate reference system. Shall be 2 or 3 according Moving Features CSV encoding specification, but Apache SIS may be tolerant to other values (depending on the backing geometry library).
      See Also:
    • geometries

      final Geometries<?> geometries
      The factory to use for creating geometries.
    • foliation

      final Foliation foliation
      Appearing order of trajectories (time or sequential), or null if unspecified.
      See Also:
    • timeEncoding

      private TimeEncoding timeEncoding
      Specifies how time is encoded in the CSV file, or null if there is no time. This field should be considered immutable after Store construction.
      See Also:
    • dissociate

      private boolean dissociate
      true if this reader should create a separated Feature instance for each line in the CSV file. By default, this is true if the CSV files does not seem to contain moving features. But the user can also force this value to true, for example for testing purposes.
    • movingFeatures

      private transient List<AbstractFeature> movingFeatures
      All parsed moving features, or null if none or if not yet parsed. If dissociate is false, then this list will be created by features(boolean) when first needed.
  • Constructor Details

    • Store

      public Store(StoreProvider provider, StorageConnector connector) throws DataStoreException
      Creates a new CSV store from the given file, URL or stream.

      If the CSV file is known to be a Moving Feature file, then the given connector should have an OptionKey.ENCODING value set to UTF-8.

      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 stream.
  • Method Details

    • rewind

      private void rewind() throws IOException
      Moves the reader position to beginning of file, if possible. We try to use the mark defined by the constructor, which is set after the last header line. If the mark is no longer valid, then we have to create a new line reader. In this latter case, we have to skip the header lines (i.e. we reproduce the constructor loop, but without parsing metadata).
      Throws:
      IOException
    • parseEnvelope

      private GeneralEnvelope parseEnvelope(List<String> elements) throws DataStoreException, org.opengis.util.FactoryException
      Parses the envelope described by the header line starting with @stboundedby. The envelope returned by this method will be stored in the envelope field.

      Example:

      This method sets timeEncoding and spatialDimensionCount as a side-effect.
      Parameters:
      elements - the line elements. The first elements should be "@stboundedby".
      Returns:
      the envelope, or null if the given list does not contain enough elements.
      Throws:
      DataStoreException
      org.opengis.util.FactoryException
    • parseFeatureType

      private DefaultFeatureType parseFeatureType(List<String> elements) throws DataStoreException
      Parses the columns metadata described by the header line starting with @columns. The feature type returned by this method will be stored in the featureType field.

      Example:

      This method needs timeEncoding and dissociate to be computed. This methods sets hasTrajectories as a side-effect.
      Parameters:
      elements - the line elements. The first element should be "@columns".
      Returns:
      the column metadata, or null if the given list does not contain enough elements.
      Throws:
      DataStoreException
    • createProperty

      private static AbstractIdentifiedType createProperty(String name, Class<?> type, int minOccurrence, int maxOccurrence, DefaultAttributeType<?>[] characteristics)
      Creates a property type for the given name and type. This is a helper method for parseFeatureType(List).
    • parseFoliation

      private Foliation parseFoliation(List<String> elements)
      Parses the metadata described by the header line starting with @foliation. The value returned by this method will be stored in the foliation field.

      Example:

      Parameters:
      elements - the line elements. The first elements should be "@foliation".
      Returns:
      the foliation metadata.
    • getIdentifier

      public Optional<org.opengis.util.GenericName> getIdentifier() throws DataStoreException
      Returns an identifier for this CSV data store. This method returns the type name, which is itself derived from the file name.
      Specified by:
      getIdentifier in interface Resource
      Overrides:
      getIdentifier in class URIDataStore
      Returns:
      identifier for this CSV data store.
      Throws:
      DataStoreException - if an error occurred while fetching the identifier.
      See Also:
    • getMetadata

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

      public Optional<org.opengis.geometry.Envelope> getEnvelope() throws DataStoreException
      Returns the spatiotemporal extent of CSV data in coordinate reference system of the CSV file.
      Specified by:
      getEnvelope in interface DataSet
      Returns:
      the spatiotemporal resource extent. May be absent if none or too costly to compute.
      Throws:
      DataStoreException - if an error occurred while reading or computing the envelope.
    • getType

      public DefaultFeatureType getType()
      Returns the type of features in the CSV file. The feature type name will be the value specified at the following path (only one such value exists for a CSV data store):
      getMetadata() / contentInfo / featureTypes / featureTypeName
      Specified by:
      getType in interface FeatureSet
      Returns:
      type of features in the CSV file.
    • features

      public final Stream<AbstractFeature> features(boolean parallel) throws DataStoreException
      Returns the stream of features.
      Specified by:
      features in interface FeatureSet
      Parameters:
      parallel - true for a parallel stream, or false for a sequential stream.
      Returns:
      a stream over all features in the CSV file.
      Throws:
      DataStoreException - if an error occurred while creating the feature stream.
    • split

      static void split(String line, List<? super String> elements)
      Splits the content of the given line around the column separator. Quotes are taken in account. The elements are added in the given list.
      Parameters:
      line - the line to parse.
      elements - an initially empty list where to add elements.
    • decode

      private static String decode(CharSequence text, int lower, int upper, boolean hasQuotes)
      Extracts a substring from the given line and replaces double quotes by single quotes.

      Departure from Moving Features specification

      The Moving Features specification said:
      Some characters may need to be escaped here. < (less than), > (greater than), " (double quotation), ‘ (single quotation), and & (ampersand) must be replaced with the entity references defined in XML. Space, tab, and comma are written in escape sequences \\s, \\t, and \\b, respectively.
      This part of the specification is currently ignored (its purpose is still unclear).
    • hasTrajectories

      final boolean hasTrajectories()
      Returns true if featureType contains a trajectory column.
    • spatialDimensionCount

      final int spatialDimensionCount()
      Returns the number of dimensions other than time in the coordinate reference system.
    • timeEncoding

      final TimeEncoding timeEncoding()
      Returns an indication of how time is encoded in the CSV file, or null if there is no time.
    • readLine

      final String readLine() throws IOException
      Reads the next line from the source CSV file.
      Throws:
      IOException
    • duplicated

      private String duplicated(String name)
      Returns an error message for a duplicated element.
    • canNotParseFile

      final String canNotParseFile()
      Returns the error message for a file that cannot be parsed. The error message will contain the line number if available.
    • errors

      private Errors errors()
      Returns the resources to use for producing error messages.
    • log

      final void log(LogRecord warning)
      Logs a warning as if it originated from the features(boolean) method. This is a callback method for FeatureIterator.
    • close

      public void close() throws DataStoreException
      Closes this data 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 this data store.
      See Also: