Class Store
java.lang.Object
org.apache.sis.storage.DataStore
org.apache.sis.internal.storage.URIDataStore
org.apache.sis.internal.storage.csv.Store
- All Implemented Interfaces:
AutoCloseable
,ResourceOnFileSystem
,StoreResource
,DataSet
,FeatureSet
,Resource
,Localized
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
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.internal.storage.URIDataStore
URIDataStore.Provider
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final char
The character at the beginning of lines to ignore in the header.private boolean
true
if this reader should create a separatedFeature
instance for each line in the CSV file.private final Charset
The character encoding, ornull
if unspecified (in which case the platform default is assumed).private final ImmutableEnvelope
The three- or four-dimensional envelope together with the CRS.(package private) final DefaultFeatureType
Description of the columns found in the CSV file.(package private) final Foliation
Appearing order of trajectories (time or sequential), ornull
if unspecified.(package private) final Geometries<?>
The factory to use for creating geometries.private boolean
true
iffeatureType
contains a trajectory column.private DefaultMetadata
The metadata object, ornull
if not yet created.(package private) static final char
The character at the beginning of metadata lines.private List<AbstractFeature>
All parsed moving features, ornull
if none or if not yet parsed.(package private) static final char
The separator between coordinate values in a coordinate tuple.private static final char
The quote character.(package private) static final char
The column separator.private BufferedReader
The reader, set by the constructor and cleared when no longer needed.private short
The number of dimensions other than time in the coordinate reference system.private TimeEncoding
Specifies how time is encoded in the CSV file, ornull
if there is no time.private static final String
The prefix for elements in the@columns
line that specify the data type, as required by the OGC CSV encoding specification.private static final String
The prefix used inhttps://www.w3.org/2009/XMLSchema/XMLSchema.xsd
file.Fields inherited from class org.apache.sis.internal.storage.URIDataStore
location
-
Constructor Summary
ConstructorsConstructorDescriptionStore
(StoreProvider provider, StorageConnector connector) Creates a new CSV store from the given file, URL or stream. -
Method Summary
Modifier and TypeMethodDescription(package private) final String
Returns the error message for a file that cannot be parsed.void
close()
Closes this data store and releases any underlying resources.private static AbstractIdentifiedType
createProperty
(String name, Class<?> type, int minOccurrence, int maxOccurrence, DefaultAttributeType<?>[] characteristics) Creates a property type for the given name and type.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.private String
duplicated
(String name) Returns an error message for a duplicated element.private Errors
errors()
Returns the resources to use for producing error messages.final Stream<AbstractFeature>
features
(boolean parallel) Returns the stream of features.Optional<org.opengis.geometry.Envelope>
Returns the spatiotemporal extent of CSV data in coordinate reference system of the CSV file.Optional<org.opengis.util.GenericName>
Returns an identifier for this CSV data store.org.opengis.metadata.Metadata
Returns the metadata associated to the CSV file, ornull
if none.getType()
Returns the type of features in the CSV file.(package private) final boolean
Returnstrue
iffeatureType
contains a trajectory column.(package private) final void
Logs a warning as if it originated from thefeatures(boolean)
method.private GeneralEnvelope
parseEnvelope
(List<String> elements) Parses the envelope described by the header line starting with@stboundedby
.private DefaultFeatureType
parseFeatureType
(List<String> elements) Parses the columns metadata described by the header line starting with@columns
.private Foliation
parseFoliation
(List<String> elements) Parses the metadata described by the header line starting with@foliation
.(package private) final String
readLine()
Reads the next line from the source CSV file.private void
rewind()
Moves the reader position to beginning of file, if possible.(package private) final int
Returns the number of dimensions other than time in the coordinate reference system.(package private) static void
Splits the content of the given line around the column separator.(package private) final TimeEncoding
Returns an indication of how time is encoded in the CSV file, ornull
if there is no time.Methods inherited from class org.apache.sis.internal.storage.URIDataStore
addTitleOrIdentifier, getComponentFiles, getOpenParameters, getOriginator, getSpecifiedPath, location, parameters
Methods inherited from class org.apache.sis.storage.DataStore
addListener, findResource, getDisplayName, getLocale, getNativeMetadata, getProvider, removeListener, setLocale, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.sis.storage.FeatureSet
subset
Methods inherited from interface org.apache.sis.storage.Resource
addListener, removeListener
-
Field Details
-
COMMENT
private static final char COMMENTThe 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 METADATAThe character at the beginning of metadata lines.- See Also:
-
QUOTE
private static final char QUOTEThe quote character. Quotes inside quoted texts must be doubled.- See Also:
-
SEPARATOR
static final char SEPARATORThe column separator.- See Also:
-
ORDINATE_SEPARATOR
static final char ORDINATE_SEPARATORThe separator between coordinate values in a coordinate tuple.- See Also:
-
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 inhttps://www.w3.org/2009/XMLSchema/XMLSchema.xsd
file. This data store implementation accepts both.- See Also:
-
XS_PREFIX
The prefix used inhttps://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
The reader, set by the constructor and cleared when no longer needed.- See Also:
-
encoding
The character encoding, ornull
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
The metadata object, ornull
if not yet created. -
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
Description of the columns found in the CSV file.- See Also:
-
hasTrajectories
private boolean hasTrajectoriestrue
iffeatureType
contains a trajectory column. This field should be considered immutable afterStore
construction.- See Also:
-
spatialDimensionCount
private short spatialDimensionCountThe 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
The factory to use for creating geometries. -
foliation
Appearing order of trajectories (time or sequential), ornull
if unspecified.- See Also:
-
timeEncoding
Specifies how time is encoded in the CSV file, ornull
if there is no time. This field should be considered immutable afterStore
construction.- See Also:
-
dissociate
private boolean dissociatetrue
if this reader should create a separatedFeature
instance for each line in the CSV file. By default, this istrue
if the CSV files does not seem to contain moving features. But the user can also force this value totrue
, for example for testing purposes. -
movingFeatures
All parsed moving features, ornull
if none or if not yet parsed. Ifdissociate
isfalse
, then this list will be created byfeatures(boolean)
when first needed.
-
-
Constructor Details
-
Store
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 thisDataStore
instance, ornull
if unspecified.connector
- information about the storage (URL, stream, etc).- Throws:
DataStoreException
- if an error occurred while opening the stream.
-
-
Method Details
-
rewind
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 theenvelope
field.Example:
This method setstimeEncoding
andspatialDimensionCount
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
Parses the columns metadata described by the header line starting with@columns
. The feature type returned by this method will be stored in thefeatureType
field.Example:
This method needstimeEncoding
anddissociate
to be computed. This methods setshasTrajectories
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 forparseFeatureType(List)
. -
parseFoliation
Parses the metadata described by the header line starting with@foliation
. The value returned by this method will be stored in thefoliation
field.Example:
- Parameters:
elements
- the line elements. The first elements should be"@foliation"
.- Returns:
- the foliation metadata.
-
getIdentifier
Returns an identifier for this CSV data store. This method returns thetype
name, which is itself derived from the file name.- Specified by:
getIdentifier
in interfaceResource
- Overrides:
getIdentifier
in classURIDataStore
- Returns:
- identifier for this CSV data store.
- Throws:
DataStoreException
- if an error occurred while fetching the identifier.- See Also:
-
getMetadata
Returns the metadata associated to the CSV file, ornull
if none.- Specified by:
getMetadata
in interfaceResource
- Specified by:
getMetadata
in classDataStore
- 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
Returns the spatiotemporal extent of CSV data in coordinate reference system of the CSV file.- Specified by:
getEnvelope
in interfaceDataSet
- 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
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 interfaceFeatureSet
- Returns:
- type of features in the CSV file.
-
features
Returns the stream of features.- Specified by:
features
in interfaceFeatureSet
- Parameters:
parallel
-true
for a parallel stream, orfalse
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
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
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()Returnstrue
iffeatureType
contains a trajectory column. -
spatialDimensionCount
final int spatialDimensionCount()Returns the number of dimensions other than time in the coordinate reference system. -
timeEncoding
Returns an indication of how time is encoded in the CSV file, ornull
if there is no time. -
readLine
Reads the next line from the source CSV file.- Throws:
IOException
-
duplicated
Returns an error message for a duplicated element. -
canNotParseFile
Returns the error message for a file that cannot be parsed. The error message will contain the line number if available. -
errors
Returns the resources to use for producing error messages. -
log
Logs a warning as if it originated from thefeatures(boolean)
method. This is a callback method forFeatureIterator
. -
close
Closes this data store and releases any underlying resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in classDataStore
- Throws:
DataStoreException
- if an error occurred while closing this data store.- See Also:
-