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 charThe character at the beginning of lines to ignore in the header.private booleantrueif this reader should create a separatedFeatureinstance for each line in the CSV file.private final CharsetThe character encoding, ornullif unspecified (in which case the platform default is assumed).private final ImmutableEnvelopeThe three- or four-dimensional envelope together with the CRS.(package private) final DefaultFeatureTypeDescription of the columns found in the CSV file.(package private) final FoliationAppearing order of trajectories (time or sequential), ornullif unspecified.(package private) final Geometries<?>The factory to use for creating geometries.private booleantrueiffeatureTypecontains a trajectory column.private DefaultMetadataThe metadata object, ornullif not yet created.(package private) static final charThe character at the beginning of metadata lines.private List<AbstractFeature>All parsed moving features, ornullif none or if not yet parsed.(package private) static final charThe separator between coordinate values in a coordinate tuple.private static final charThe quote character.(package private) static final charThe column separator.private BufferedReaderThe reader, set by the constructor and cleared when no longer needed.private shortThe number of dimensions other than time in the coordinate reference system.private TimeEncodingSpecifies how time is encoded in the CSV file, ornullif there is no time.private static final StringThe prefix for elements in the@columnsline that specify the data type, as required by the OGC CSV encoding specification.private static final StringThe prefix used inhttps://www.w3.org/2009/XMLSchema/XMLSchema.xsdfile.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 StringReturns the error message for a file that cannot be parsed.voidclose()Closes this data store and releases any underlying resources.private static AbstractIdentifiedTypecreateProperty(String name, Class<?> type, int minOccurrence, int maxOccurrence, DefaultAttributeType<?>[] characteristics) Creates a property type for the given name and type.private static Stringdecode(CharSequence text, int lower, int upper, boolean hasQuotes) Extracts a substring from the given line and replaces double quotes by single quotes.private Stringduplicated(String name) Returns an error message for a duplicated element.private Errorserrors()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.MetadataReturns the metadata associated to the CSV file, ornullif none.getType()Returns the type of features in the CSV file.(package private) final booleanReturnstrueiffeatureTypecontains a trajectory column.(package private) final voidLogs a warning as if it originated from thefeatures(boolean)method.private GeneralEnvelopeparseEnvelope(List<String> elements) Parses the envelope described by the header line starting with@stboundedby.private DefaultFeatureTypeparseFeatureType(List<String> elements) Parses the columns metadata described by the header line starting with@columns.private FoliationparseFoliation(List<String> elements) Parses the metadata described by the header line starting with@foliation.(package private) final StringreadLine()Reads the next line from the source CSV file.private voidrewind()Moves the reader position to beginning of file, if possible.(package private) final intReturns the number of dimensions other than time in the coordinate reference system.(package private) static voidSplits the content of the given line around the column separator.(package private) final TimeEncodingReturns an indication of how time is encoded in the CSV file, ornullif there is no time.Methods inherited from class org.apache.sis.internal.storage.URIDataStore
addTitleOrIdentifier, getComponentFiles, getOpenParameters, getOriginator, getSpecifiedPath, location, parametersMethods inherited from class org.apache.sis.storage.DataStore
addListener, findResource, getDisplayName, getLocale, getNativeMetadata, getProvider, removeListener, setLocale, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sis.storage.FeatureSet
subsetMethods 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@columnsline 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.xsdfile. This data store implementation accepts both.- See Also:
-
XS_PREFIX
The prefix used inhttps://www.w3.org/2009/XMLSchema/XMLSchema.xsdfile. 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, ornullif 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, ornullif 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 hasTrajectoriestrueiffeatureTypecontains a trajectory column. This field should be considered immutable afterStoreconstruction.- 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), ornullif unspecified.- See Also:
-
timeEncoding
Specifies how time is encoded in the CSV file, ornullif there is no time. This field should be considered immutable afterStoreconstruction.- See Also:
-
dissociate
private boolean dissociatetrueif this reader should create a separatedFeatureinstance for each line in the CSV file. By default, this istrueif 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, ornullif none or if not yet parsed. Ifdissociateisfalse, 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.ENCODINGvalue set to UTF-8.- Parameters:
provider- the factory that created thisDataStoreinstance, ornullif 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 theenvelopefield.Example:
This method setstimeEncodingandspatialDimensionCountas a side-effect.- Parameters:
elements- the line elements. The first elements should be"@stboundedby".- Returns:
- the envelope, or
nullif the given list does not contain enough elements. - Throws:
DataStoreExceptionorg.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 thefeatureTypefield.Example:
This method needstimeEncodinganddissociateto be computed. This methods setshasTrajectoriesas a side-effect.- Parameters:
elements- the line elements. The first element should be"@columns".- Returns:
- the column metadata, or
nullif 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 thefoliationfield.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 thetypename, which is itself derived from the file name.- Specified by:
getIdentifierin interfaceResource- Overrides:
getIdentifierin 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, ornullif none.- Specified by:
getMetadatain interfaceResource- Specified by:
getMetadatain classDataStore- Returns:
- the metadata associated to the CSV file, or
nullif 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:
getEnvelopein 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:
getTypein interfaceFeatureSet- Returns:
- type of features in the CSV file.
-
features
Returns the stream of features.- Specified by:
featuresin interfaceFeatureSet- Parameters:
parallel-truefor a parallel stream, orfalsefor 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()ReturnstrueiffeatureTypecontains 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, ornullif 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:
closein interfaceAutoCloseable- Specified by:
closein classDataStore- Throws:
DataStoreException- if an error occurred while closing this data store.- See Also:
-