Class WKTDictionary
- All Implemented Interfaces:
AuthorityFactory, Factory
create(…) method is invoked for the first time for a given key.
Sub-classing and instantiation
Newly constructedWKTDictionary are initially empty.
The dictionary can be populated in the following ways:
- Invoke
load(BufferedReader)for reading definitions from file(s). - Invoke
addDefinitions(Stream)for providing definitions from an arbitrary source. - Override
fetchDefinition(DefaultIdentifier)in a subclass for fetching WKT definitions on-the-fly (for example from the"spatial_ref_sys"table of a spatial database.
fetchDefinition(…) is not overridden
because WKTDictionary does not implement any of the
CRSAuthorityFactory,
CSAuthorityFactory or
DatumAuthorityFactory.
The choice of interfaces to implement is left to subclasses.
Example
Extend the set of Coordinate Reference Systems recognized byCRS.forCode(String).
The additional CRS are defined by Well-Known Text strings in a "MyCRS.txt" file.
First step is to create a CRS factory with those definitions:
public final class MyCRS extends WKTDictionary implements CRSAuthorityFactory {
MyCRS() throws IOException, FactoryException {
super(new DefaultCitation("MyAuthority"));
try (BufferedReader source = Files.newBufferedReader(Path.of("MyCRS.txt"))) {
load(source);
}
}
}
module-info.java file
as a provider of the org.opengis.referencing.crs.CRSAuthorityFactory service.
That file shall contain the class name of above MyCRS class.
Errors management
Well-Known Text parsing is performed in two steps, each of them executed at a different time:Early validation
WKT strings added byload(…) or addDefinitions(…) methods are verified
for matching quotes, balanced parenthesis or brackets, and valid number or date formats.
If a syntax error is detected, the loading process is interrupted at the point the error occurred;
CRS definitions after the error location are not loaded.
However, WKT keywords and geodetic parameters (e.g. map projections) are not validated at this stage.
Late validation
WKT keywords and geodetic parameters inside WKT elements are validated only whencreateObject(String)
is invoked. If an error occurs at this stage, only the CRS (or other geodetic object) for the code given to
the createFoo(…) method become invalid. Objects associated with other codes are not impacted.
Multi-threading
This class is thread-safe but not necessarily concurrent. This class is designed for a relatively small number of WKT; it is not a replacement for database-backed factory such asEPSGFactory.- Since:
- 1.1
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDefinitions(Stream<String> objects) Adds definitions of CRS (or other geodetic objects) from Well-Known Texts.createObject(String code) Returns an arbitrary object from a code.protected StringfetchDefinition(DefaultIdentifier identifier) Fetches the Well-Known Text for a user-specified identifier not found in thisWKTDictionary.Returns the authority or specification that defines the codes recognized by this factory.getAuthorityCodes(Class<? extends IdentifiedObject> type) Returns the set of authority codes for objects of the given type.Returns all namespaces recognized by this factory.getDescriptionText(Class<? extends IdentifiedObject> type, String code) Gets a description of the object corresponding to a code.voidload(BufferedReader source) Adds to this factory all definitions read from the given source.Methods inherited from class GeodeticAuthorityFactory
createCartesianCS, createCompoundCRS, createCoordinateOperation, createCoordinateReferenceSystem, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createDatum, createDatumEnsemble, createDerivedCRS, createEllipsoid, createEllipsoidalCS, createEngineeringCRS, createEngineeringDatum, createExtent, createFromCoordinateReferenceSystemCodes, createGeocentricCRS, createGeodeticDatum, createGeographicCRS, createImageCRS, createImageDatum, createObject, createOperationMethod, createParameterDescriptor, createParametricCRS, createParametricCS, createParametricDatum, createPolarCS, createPrimeMeridian, createProjectedCRS, createSphericalCS, createTemporalCRS, createTemporalDatum, createTimeCS, createUnit, createVerticalCRS, createVerticalCS, createVerticalDatum, getDescriptionText, newIdentifiedObjectFinder, toString, trimNamespaceModifier and TypeMethodDescriptioncreateCartesianCS(String code) Creates a 2- or 3-dimensional Cartesian coordinate system made of straight orthogonal axes.createCompoundCRS(String code) Creates a CRS describing the position of points through two or more independent coordinate reference systems.Creates an operation for transforming coordinates in the source CRS to coordinates in the target CRS.Creates an arbitrary coordinate reference system from a code.Creates an arbitrary coordinate system from a code.Creates a coordinate system axis with name, direction, unit and range of values.createCylindricalCS(String code) Creates a 3-dimensional coordinate system made of a polar coordinate system extended by a straight perpendicular axis.createDatum(String code) Creates an arbitrary datum from a code.createDatumEnsemble(String code) Creates an arbitrary datum ensemble from a code.createDerivedCRS(String code) Creates a CRS that is defined by its coordinate conversion from another CRS (not by a datum).createEllipsoid(String code) Creates a geometric figure that can be used to describe the approximate shape of the earth.createEllipsoidalCS(String code) Creates a 2- or 3-dimensional coordinate system for geodetic latitude and longitude, sometimes with ellipsoidal height.createEngineeringCRS(String code) Creates a 1-, 2- or 3-dimensional contextually local coordinate reference system.Creates a datum defining the origin of an engineering coordinate reference system.createExtent(String code) Creates information about spatial, vertical, and temporal extent (usually a domain of validity) from a code.createFromCoordinateReferenceSystemCodes(String sourceCRS, String targetCRS) Creates operations from source and target coordinate reference system codes.createGeocentricCRS(String code) Creates a 3-dimensional coordinate reference system with the origin at the approximate centre of mass of the earth.createGeodeticDatum(String code) Creates a datum defining the location and orientation of an ellipsoid that approximates the shape of the earth.createGeographicCRS(String code) Creates a 2- or 3-dimensional coordinate reference system based on an ellipsoidal approximation of the geoid.createImageCRS(String code) Deprecated.createImageDatum(String code) Deprecated.TheImageDatumclass has been removed in ISO 19111:2019.final <T extends IdentifiedObject>
TcreateObject(Class<T> type, String code) Returns an object of the specified type from a code.Creates a description of the algorithm and parameters used to perform a coordinate operation.Creates a definition of a single parameter used by an operation method.createParametricCRS(String code) Creates a 1-dimensional parametric coordinate reference system.createParametricCS(String code) Creates a 1-dimensional parametric coordinate system.Creates a datum defining the origin of a parametric coordinate reference system.createPolarCS(String code) Creates a 2-dimensional coordinate system for coordinates represented by a distance from the origin and an angle from a fixed direction.createPrimeMeridian(String code) Creates a prime meridian defining the origin from which longitude values are determined.createProjectedCRS(String code) Creates a 2-dimensional coordinate reference system used to approximate the shape of the earth on a planar surface.createSphericalCS(String code) Creates a 3-dimensional coordinate system with one distance measured from the origin and two angular coordinates.createTemporalCRS(String code) Creates a 1-dimensional coordinate reference system used for the recording of time.createTemporalDatum(String code) Creates a datum defining the origin of a temporal coordinate reference system.createTimeCS(String code) Creates a 1-dimensional coordinate system for time elapsed in the specified time units from a specified time origin.Unit<?> createUnit(String code) Creates an unit of measurement from a code.createVerticalCRS(String code) Creates a 1-dimensional coordinate reference system used for recording heights or depths.createVerticalCS(String code) Creates a 1-dimensional coordinate system for heights or depths of points.createVerticalDatum(String code) Creates a datum identifying a particular reference level surface used as a zero-height surface.getDescriptionText(String code) Deprecated.This method is ambiguous because the EPSG geodetic registry may allocate the same code to different kinds of object.Creates a finder which can be used for looking up unidentified objects.Returns a string representation of this factory for debugging purpose only.protected final StringtrimNamespace(String code) Trims the namespace, if present.Methods inherited from class AbstractFactory
getVendorModifier and TypeMethodDescriptionReturns the implementer of this factory, ornullif unknown.
-
Field Details
-
parser
The parser to use for creating geodetic objects from WKT definitions. Subclasses can modify theWKTFormatconfiguration in their constructor, but should not use it directly after construction (for thread safety reasons).
-
-
Constructor Details
-
WKTDictionary
Creates an initially empty factory. The authority can specified explicitly or inferred from the WKTs. In the latter case (when the given authority isnull), an authority will be inferred from allID[…]orAUTHORITY[…]elements found in WKT strings as below, in preference order:- Most frequent
CITATION[…]value. - If there is no citation, then most frequent code space
in
ID[…]orAUTHORITY[…]elements.
load(BufferedReader)oraddDefinitions(Stream)after construction.- Parameters:
authority- organization that defines the codes recognized by this factory, ornull.
- Most frequent
-
-
Method Details
-
load
Adds to this factory all definitions read from the given source. Each Coordinate Reference System (or other geodetic object) is defined by a string in WKT format. The key associated with each object is given by theID[…]orAUTHORITY[…]element, which is typically the last element of a WKT string and is mandatory for definitions in this file.WKT strings can span many lines. All lines after the first line shall be indented with at least one white space. Non-indented lines start new definitions.
Blank lines and lines starting with the
#character (ignoring white spaces) are ignored.Aliases for WKT fragments
Files with more than one WKT definition tend to repeat the same WKT fragments many times. For example, the sameBaseGeogCRS[…]element may be repeated in everyProjectedCRSdefinitions. Redundant fragments can be replaced by aliases for making the file more compact, easier to read, faster to parse and with smaller memory footprint.Each line starting with "
SET <identifier>=<WKT>" defines an alias for a fragment of WKT string. The WKT can span many lines as described above. Aliases are local to the file where they are defined. Aliases can be expanded in other WKT strings by "$<identifier>".Validation
This method verifies that definitions have matching quotes, balanced parenthesis or brackets, and valid number or date formats. It does not verify WKT keywords or geodetic parameters. See class javadoc for more details.Example
An example is available here.- Parameters:
source- the source of WKT definitions.- Throws:
FactoryException- if the definition file cannot be read.
-
addDefinitions
Adds definitions of CRS (or other geodetic objects) from Well-Known Texts. Blank strings are ignored. Each non-blankStringshall contain the complete definition of exactly one geodetic object. A geodetic object cannot have its definition split in two or moreStrings.The key associated with each object is given by the
ID[…]orAUTHORITY[…]element, which is typically the last element of a WKT string and is mandatory. WKT strings can contain line separators for human readability.- Parameters:
objects- CRS (or other geodetic objects) definitions as WKT strings.- Throws:
FactoryException- if a WKT cannot be parsed, or does not contain anID[…]orAUTHORITY[…]element, or if the samecodespace:version:codetuple is used for two objects.
-
fetchDefinition
Fetches the Well-Known Text for a user-specified identifier not found in thisWKTDictionary. Subclasses can override this method if WKT strings are not loaded or specified in advance, but instead fetched when first needed. An example of such scenario is WKTs provided by the"spatial_ref_sys"table of a spatial database. If no WKT is found for the given identifier, then this method returnsnull.On input,
identifiercontains only the pieces of information provided by user. For example if user invokedcreateGeographicCRS("Foo"), then the identifier code will be"Foo"but the codespace and version will be undefined (null). On output,identifiershould be completed with missing code space and version (if available).Overriding
The default implementation returnsnull. If a subclass overrides this method, then it should also overridegetAuthorityCodes(Class)becauseWKTDictionarydoes not know the codes that this method can recognize.- Parameters:
identifier- the code specified by user, possible with code space and version.- Returns:
- Well-Known Text (WKT) for the given identifier, or
nullif none. - Throws:
FactoryException- if an error occurred while fetching the WKT.
-
getAuthority
Returns the authority or specification that defines the codes recognized by this factory. This is the first of the following values, in preference order:- The authority explicitly specified at construction time.
- A citation built from the most frequent value found in
CITATIONelements. - A citation built from the most frequent value found in
IDorAUTHORITYelements.
- Specified by:
getAuthorityin interfaceAuthorityFactory- Specified by:
getAuthorityin classGeodeticAuthorityFactory- Returns:
- the organization responsible for CRS definitions, or
nullif unknown. - See Also:
-
getCodeSpaces
Returns all namespaces recognized by this factory. Those namespaces can appear before codes in calls tocreateFoo(String)methods, for example"ESRI"in"ESRI:102018". Namespaces are case-insensitive.- Overrides:
getCodeSpacesin classGeodeticAuthorityFactory- Returns:
- the namespaces recognized by this factory.
-
getAuthorityCodes
public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) throws FactoryException Returns the set of authority codes for objects of the given type. Thetypeargument specifies the base type of identified objects.- Parameters:
type- the spatial reference objects type.- Returns:
- the set of authority codes for spatial reference objects of the given type.
- Throws:
FactoryException- if an error occurred while fetching the codes.
-
getDescriptionText
public Optional<InternationalString> getDescriptionText(Class<? extends IdentifiedObject> type, String code) throws FactoryException Gets a description of the object corresponding to a code.- Overrides:
getDescriptionTextin classGeodeticAuthorityFactory- Parameters:
type- the type of object for which to get a description.code- value allocated by authority.- Returns:
- a description of the object, or
nullifnullif none. - Throws:
NoSuchAuthorityCodeException- if the specifiedcodewas not found.FactoryException- if the query failed for some other reason.- Since:
- 1.5
-
createObject
Returns an arbitrary object from a code.- Specified by:
createObjectin interfaceAuthorityFactory- Specified by:
createObjectin classGeodeticAuthorityFactory- Parameters:
code- value allocated by authority.- Returns:
- the object for the given code.
- Throws:
NoSuchAuthorityCodeException- if the specifiedcodewas not found.FactoryException- if the object creation failed for some other reason.- See Also:
-
ImageCRSclass has been removed in ISO 19111:2019.