public class Formatter extends Object
Formattable
objects as Well
Known Text (WKT).
A formatter is constructed with a specified set of symbols. The locale associated with the symbols is used for querying authority titles.
Constructor and Description |
---|
Formatter()
Creates a new instance of the formatter with the default symbols.
|
Formatter(Symbols symbols)
Creates a new instance of the formatter.
|
Formatter(Symbols symbols,
int indentation)
Creates a new instance of the formatter with the specified indentation width.
|
Modifier and Type | Method and Description |
---|---|
void |
append(CodeList code)
Append a code list to the WKT.
|
void |
append(double number)
Append a floating point number.
|
void |
append(Formattable formattable)
Append the specified
Formattable object. |
void |
append(GeneralParameterValue parameter)
Append a parameter in WKT form.
|
void |
append(IdentifiedObject info)
Append the specified OpenGIS's
IdentifiedObject object. |
void |
append(int number)
Append an integer number.
|
void |
append(MathTransform transform)
Append the specified math transform.
|
void |
append(String text)
Append a character string.
|
void |
append(Unit<?> unit)
Appends a unit in WKT form.
|
void |
clear()
Clear this formatter.
|
Unit<Angle> |
getAngularUnit()
The angular unit for formatting measures, or
null for the "natural" unit of each WKT
element. |
Citation |
getAuthority() |
Identifier |
getIdentifier(IdentifiedObject info)
Returns the preferred identifier for the specified object.
|
Unit<Length> |
getLinearUnit()
The linear unit for formatting measures, or
null for the "natural" unit of each WKT
element. |
String |
getName(IdentifiedObject info)
Returns the preferred name for the specified object.
|
boolean |
isInvalidWKT()
Returns
true if the WKT in this formatter is not strictly compliant to the WKT
specification. |
static void |
main(String[] args)
Set the preferred indentation from the command line.
|
void |
setAngularUnit(Unit<Angle> unit)
Set the angular unit for formatting measures.
|
void |
setAuthority(Citation authority) |
void |
setInvalidWKT(Class<?> unformattable)
Set a flag marking the current WKT as not strictly compliant to the WKT
specification.
|
void |
setLinearUnit(Unit<Length> unit)
Set the unit for formatting linear measures.
|
String |
toString()
Returns the WKT in its current state.
|
public Formatter()
public Formatter(Symbols symbols)
symbols
- The symbols.public Formatter(Symbols symbols, int indentation)
FormattableObject#SINGLE_LINE
, then the
whole WKT will be formatted on a single line.symbols
- The symbols.indentation
- The amount of spaces to use in indentation. Typical values are 2 or 4.public Citation getAuthority()
public void setAuthority(Citation authority)
public void append(Formattable formattable)
Formattable
object. This method will automatically append the
keyword (e.g. "GEOCS"
), the name and the authority code, and will invokes
formattable.formatWKT(this)
for completing the
inner part of the WKT.formattable
- The formattable object to append to the WKT.public void append(IdentifiedObject info)
IdentifiedObject
object.info
- The info object to append to the WKT.public void append(MathTransform transform)
transform
- The transform object to append to the WKT.public void append(CodeList code)
code
- The code list to format.public void append(GeneralParameterValue parameter)
parameter
- The parameter to format.public void append(int number)
number
- The integer to format.public void append(double number)
number
- The floating point value to format.public void append(Unit<?> unit)
append(SI.KILOMETER)
can append "
UNIT["km", 1000]
" to the WKT.unit
- The unit to append.IllegalArgumentException
- if the provided unit is notpublic void append(String text)
text
- The string to format.public Identifier getIdentifier(IdentifiedObject info)
null
.info
- The object to looks for a preferred identifier.null
if none.public String getName(IdentifiedObject info)
info
- The object to looks for a preferred name.public Unit<Length> getLinearUnit()
null
for the "natural" unit of each WKT
element.null
.public void setLinearUnit(Unit<Length> unit)
unit
- The new unit, or null
.public Unit<Angle> getAngularUnit()
null
for the "natural" unit of each WKT
element. This value is set for example by "GEOGCS", which force its enclosing "PRIMEM" to
take the same units than itself.null
.public void setAngularUnit(Unit<Angle> unit)
unit
- The new unit, or null
.public boolean isInvalidWKT()
true
if the WKT in this formatter is not strictly compliant to the WKT
specification. This method returns true
if setInvalidWKT(java.lang.Class<?>)
has been
invoked at least once. The action to take regarding invalid WKT is caller-dependant. For
example Formattable.toString()
will accepts loose WKT formatting and ignore this flag,
while Formattable.toWKT()
requires strict WKT formatting and will thrown an exception
if this flag is set.true
if the WKT is invalid.public void setInvalidWKT(Class<?> unformattable)
Formattable.formatWKT(org.geotools.referencing.wkt.Formatter)
methods when the
object to format is more complex than what the WKT specification allows. For example this
method is invoked when an engineering CRS uses different unit for each axis, An application can tests isInvalidWKT()
later for checking WKT validity.unformattable
- The type of the component that can't be formatted, for example EngineeringCRS
.UnformattableObjectException.getUnformattableClass()
public String toString()
public void clear()
Formatter
object is ready for formatting a new object.public static void main(String[] args)
Formattable.toWKT()
when no indentation were explicitly requested. This method can be
invoked from the command line using the following syntax:
java org.geotools.referencing.wkt.Formatter -indentation=
<preferred
indentation>
args
- The command-line arguments.Copyright © 1996–2019 Geotools. All rights reserved.