Object
ReferencingFormat
Parses and format referencing objects in Well Known Text, JSON or PROJ format.
Differences with
WKT formatting can be done more easily by invoking the
ReferencingFormat
allows choice of the format (WKT, JSON or PROJ), the format version
(e.g. WKT 2 versus WKT 1), or the "flavor" when there are different interpretations of the same format.
ReferencingFormat
provides also some control on the formatting process, for example the
number of spaces in indentations.
Differences with toWKT()
WKT formatting can be done more easily by invoking the IdentifiedObject.toWKT()
method.
However the toWKT()
method, like the toString()
method, uses only the information
available in the object to format. This ReferencingFormat
class differs in that it may
complete those information by an access to the database.
Limitations
ReferencingFormat
is not thread-safe. If used in a multi-thread environment,
then each thread should have its own instance, or synchronization shall be done by the user.
- Since:
- 1.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Controls some aspects in formatting referencing objects as Well Known Text (WKT), JSON or PROJ strings. -
Constructor Summary
ConstructorDescriptionCreates a new formatter initialized to default configuration. -
Method Summary
Modifier and TypeMethodDescriptionFormats the given object.Returns the current convention used by this formatter.int
Returns the number of spaces in indentations when multilines output is enabled.boolean
Returns whether the output will be written in many lines.boolean
Returns whether the operation should fail if it can not be performed using strictly standard compliant WKT format.Returns the warnings emitted during the last parsing operation.Parses the given characters string.void
setConvention
(ReferencingFormat.Convention convention) Sets the convention to use for this formatter.void
setIndentationWidth
(int n) Sets the number of spaces in indentations when multilines output is enabled.void
setMultiLine
(boolean multiline) Sets whether the output will be written in many lines.void
setStrict
(boolean strict) Sets whether the operation should fail if it can not be performed using strictly standard compliant WKT format.
-
Constructor Details
-
ReferencingFormat
public ReferencingFormat()Creates a new formatter initialized to default configuration. The default configuration usesReferencingFormat.Convention.WKT
and formats the WKT in a multi-lines layout.
-
-
Method Details
-
getConvention
Returns the current convention used by this formatter. The default value isReferencingFormat.Convention.WKT
, which stands for the latest supported WKT version (currently WKT 2 as published in 2019).- Returns:
- the current convention.
-
setConvention
Sets the convention to use for this formatter. This method allows to select a different format (e.g. JSON or PROJ) or a different flavor of legacy WKT 1 format. For example the conventions can be set toWKT1_ESRI
if the legacy WKT format is desired instead than the one standardized by ISO 19162.If this setter is not invoked, then the default value is
ReferencingFormat.Convention.WKT
.- Parameters:
convention
- the new convention to apply.
-
getMultiLine
public boolean getMultiLine()Returns whether the output will be written in many lines.- Returns:
- whether the WKT will use multi-line layout.
-
setMultiLine
public void setMultiLine(boolean multiline) Sets whether the output will be written in many lines. If this setter is not invoked, then the default value istrue
.- Parameters:
multiline
- whether the WKT will use multi-line layout.
-
getIndentationWidth
public int getIndentationWidth()Returns the number of spaces in indentations when multilines output is enabled.- Returns:
- number of spaces for each indentation level.
-
setIndentationWidth
public void setIndentationWidth(int n) Sets the number of spaces in indentations when multilines output is enabled. If this setter is not invoked, then the default value is 4.- Parameters:
n
- number of spaces for each indentation level.
-
getStrict
public boolean getStrict()Returns whether the operation should fail if it can not be performed using strictly standard compliant WKT format.- Returns:
- whether to enforce strictly standard format.
-
setStrict
public void setStrict(boolean strict) Sets whether the operation should fail if it can not be performed using strictly standard compliant WKT format.- Parameters:
strict
- whether to enforce strictly standard format.
-
format
Formats the given object. It must be a PROJ implementation.- Parameters:
object
- the PROJ object to format.- Returns:
- the given object in WKT, JSON or PROJ format.
- Throws:
UnformattableObjectException
- if the given object can not be formatted.
-
parse
Parses the given characters string. The format (WKT, PROJ) must be the format specified by the last call tosetConvention(Convention)
. If the given string contains some non-fatal errors, warnings can be obtained bygetWarnings()
.- Parameters:
text
- the object definition to parse.- Returns:
- object parsed from the given characters string.
- Throws:
UnparsableObjectException
- if an error occurred during parsing.- See Also:
-
getWarnings
Returns the warnings emitted during the last parsing operation. If no warning occurred, then this method returns an empty list.- Returns:
- the warnings that occurred during the last parsing operation.
-