Package org.apache.sis.internal.storage
Class PRJDataStore
java.lang.Object
org.apache.sis.storage.DataStore
org.apache.sis.internal.storage.URIDataStore
org.apache.sis.internal.storage.PRJDataStore
- All Implemented Interfaces:
AutoCloseable
,ResourceOnFileSystem
,StoreResource
,Resource
,Localized
- Direct Known Subclasses:
RasterStore
,WorldFileStore
A data store for a file or URI accompanied by an auxiliary file of the same name with
.prj
extension.
If the auxiliary file is absent, DataOptionKey.DEFAULT_CRS
is used as a fallback.
The WKT 1 variant used for parsing the "*.prj"
file is the variant used by "World Files" and GDAL;
this is not the standard specified by OGC 01-009 (they differ in there interpretation of units of measurement).
It is still possible to create a data store with a ReadableByteChannel
,
InputStream
or Reader
, in which case the URIDataStore.location will
be null and the CRS defined by the DataOptionKey
will be used.
- Since:
- 1.2
- Version:
- 1.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final class
Content of a file read byreadAuxiliaryFile(String)
.static class
Provider forPRJDataStore
instances. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.opengis.referencing.crs.CoordinateReferenceSystem
The coordinate reference system.protected final Charset
Character encoding in*.prj
or other auxiliary files, ornull
for the JVM default (usually UTF-8).private final Locale
private static final int
Maximal length (in bytes) of auxiliary files.protected static final String
The filename extension of"*.prj"
files.private final TimeZone
Timezone for dates in*.prj
or other auxiliary files, ornull
for UTC.Fields inherited from class org.apache.sis.internal.storage.URIDataStore
location
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
PRJDataStore
(DataStoreProvider provider, StorageConnector connector) Creates a new data store. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
deleteAuxiliaryFile
(String extension) Deletes the auxiliary file with the given extension if it exists.private static String
getBaseFilename
(Path path) Returns the filename of the given path without the file suffix.Path[]
Returns the URIDataStore.location as aPath
component together with auxiliary files.Optional<org.opengis.parameter.ParameterValueGroup>
Returns the parameters used to open this data store.protected final Path[]
listComponentFiles
(String... auxiliaries) Returns the URIDataStore.location as aPath
component together with auxiliary files.protected final PRJDataStore.AuxiliaryContent
readAuxiliaryFile
(String extension) Reads the content of the auxiliary file with the specified extension.protected final void
readPRJ()
Reads the"*.prj"
auxiliary file.protected final BufferedWriter
writeAuxiliaryFile
(String extension) Creates a writer for an auxiliary file with the specified extension.protected final void
writePRJ()
Writes the"*.prj"
auxiliary file ifcrs
is non-null.Methods inherited from class org.apache.sis.internal.storage.URIDataStore
addTitleOrIdentifier, getIdentifier, getOriginator, getSpecifiedPath, location, parameters
Methods inherited from class org.apache.sis.storage.DataStore
addListener, close, findResource, getDisplayName, getLocale, getMetadata, 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.Resource
addListener, getMetadata, removeListener
-
Field Details
-
MAXIMAL_LENGTH
private static final int MAXIMAL_LENGTHMaximal length (in bytes) of auxiliary files. This is an arbitrary restriction, we could let the buffer growth indefinitely instead. But a large auxiliary file is probably an error and we do not want anOutOfMemoryError
because of that.- See Also:
-
PRJ
The filename extension of"*.prj"
files.- See Also:
-
encoding
Character encoding in*.prj
or other auxiliary files, ornull
for the JVM default (usually UTF-8). -
locale
The locale for texts in*.prj
or other auxiliary files, ornull
forLocale.ROOT
(usually English). This locale is not used for parsing numbers or dates. -
timezone
Timezone for dates in*.prj
or other auxiliary files, ornull
for UTC. -
crs
protected org.opengis.referencing.crs.CoordinateReferenceSystem crsThe coordinate reference system. This is initialized on the value provided byDataOptionKey.DEFAULT_CRS
at construction time, and is modified later if a"*.prj"
file is found.
-
-
Constructor Details
-
PRJDataStore
protected PRJDataStore(DataStoreProvider provider, StorageConnector connector) throws DataStoreException Creates a new data store. This constructor does not open the file, so subclass constructors can decide whether to open in read-only or read/write mode.The following options are recognized:
DataOptionKey.DEFAULT_CRS
: default CRS if no auxiliary"*.prj"
file is found.OptionKey.ENCODING
: encoding of the"*.prj"
file. Default is the JVM default.OptionKey.TIMEZONE
: timezone of dates in the"*.prj"
file. Default is UTC.OptionKey.LOCALE
: locale for texts in the"*.prj"
file. Default is English.
- Parameters:
provider
- the factory that created thisPRJDataStore
instance, ornull
if unspecified.connector
- information about the storage (URL, stream, reader instance, etc).- Throws:
DataStoreException
- if an error occurred while creating the data store for the given storage.
-
-
Method Details
-
readPRJ
Reads the"*.prj"
auxiliary file. If the file is not found, then this method does nothing andcrs
keeps its current value (usually the default value found at construction time).This method does not verify if it has been invoked multiple time. Caller should track whether the data store has been initialized.
- Throws:
DataStoreException
- if an error occurred while reading the file.
-
readAuxiliaryFile
protected final PRJDataStore.AuxiliaryContent readAuxiliaryFile(String extension) throws IOException, DataStoreException Reads the content of the auxiliary file with the specified extension. This method uses the same URI thanURIDataStore.location
, except for the extension which is replaced by the given value. This method is suitable for reasonably small files. An arbitrary size limit is applied for safety.- Parameters:
extension
- the filename extension of the auxiliary file to open.- Returns:
- the file content together with the source, or
null
if none. Should be short-lived. - Throws:
NoSuchFileException
- if the auxiliary file has not been found (when opened from path).FileNotFoundException
- if the auxiliary file has not been found (when opened from URL).IOException
- if another error occurred while opening the stream.DataStoreException
- if the auxiliary file content seems too large.
-
writePRJ
Writes the"*.prj"
auxiliary file ifcrs
is non-null. Ifcrs
is null and the auxiliary file exists, it is deleted.WKT version used
Current version writes the CRS in WKT 2 format. This is not the common practice, which uses WKT 1. But the WKT 1 variant used by the common practice is not the standard format defined by OGC 01-009. It is more likeConvention.WKT1_IGNORE_AXES
, which has many ambiguity problems. The WKT 2 format fixes those ambiguities. We hope that major software have updated their referencing engine and can now parse WKT 2 as well as WKT 1.- Throws:
DataStoreException
- if an error occurred while writing the file.
-
writeAuxiliaryFile
protected final BufferedWriter writeAuxiliaryFile(String extension) throws IOException, DataStoreException Creates a writer for an auxiliary file with the specified extension. This method uses the same path thanURIDataStore.location
, except for the extension which is replaced by the given value.- Parameters:
extension
- the filename extension of the auxiliary file to write.- Returns:
- a stream opened on the specified file.
- Throws:
UnknownServiceException
- if noPath
orURI
is available.DataStoreException
- if the auxiliary file cannot be created.IOException
- if another error occurred while opening the stream.
-
deleteAuxiliaryFile
Deletes the auxiliary file with the given extension if it exists. If the auxiliary file does not exist, then this method does nothing.- Parameters:
extension
- the filename extension of the auxiliary file to delete.- Throws:
DataStoreException
- if the auxiliary file is not on a supported file system.IOException
- if an error occurred while deleting the file.
-
getComponentFiles
Returns the URIDataStore.location as aPath
component together with auxiliary files. The default implementation does the same computation as the super-class, then adds the sibling file with".prj"
extension if it exists.- Specified by:
getComponentFiles
in interfaceResourceOnFileSystem
- Overrides:
getComponentFiles
in classURIDataStore
- Returns:
- the main file and auxiliary files as paths, or an empty array if unknown.
- Throws:
DataStoreException
- if the URI cannot be converted to aPath
.
-
listComponentFiles
Returns the URIDataStore.location as aPath
component together with auxiliary files. This method computes the path to the main file asURIDataStore.getComponentFiles()
, then add the sibling files with all extensions specified in theauxiliaries
argument. Each auxiliary file is tested for existence. Paths that are not regular files are omitted. This is a helper method forgetComponentFiles()
implementation.- Parameters:
auxiliaries
- filename extension (without leading dot) of all auxiliary files. Null elements are silently ignored.- Returns:
- the URI as a path, followed by all auxiliary files that exist.
- Throws:
DataStoreException
- if the URI cannot be converted to aPath
.
-
getBaseFilename
Returns the filename of the given path without the file suffix. The returned string always ends in'.'
, making it ready for concatenation of a new suffix. -
getOpenParameters
Returns the parameters used to open this data store.- Overrides:
getOpenParameters
in classURIDataStore
- Returns:
- parameters used for opening this
DataStore
. - See Also:
-