Class ReferencingFormat

Object
ReferencingFormat

public class ReferencingFormat extends Object
Parses and format referencing objects in Well Known Text, JSON or PROJ format. 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
  • Constructor Details

    • ReferencingFormat

      public ReferencingFormat()
      Creates a new formatter initialized to default configuration. The default configuration uses ReferencingFormat.Convention.WKT and formats the WKT in a multi-lines layout.
  • Method Details

    • getConvention

      public ReferencingFormat.Convention getConvention()
      Returns the current convention used by this formatter. The default value is ReferencingFormat.Convention.WKT, which stands for the latest supported WKT version (currently WKT 2 as published in 2019).
      Returns:
      the current convention.
    • setConvention

      public void setConvention(ReferencingFormat.Convention convention)
      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 to WKT1_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 is true.
      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

      public String format(Object object) throws UnformattableObjectException
      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

      public Object parse(String text) throws UnparsableObjectException
      Parses the given characters string. The format (WKT, PROJ) must be the format specified by the last call to setConvention(Convention). If the given string contains some non-fatal errors, warnings can be obtained by getWarnings().
      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

      public List<String> 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.