|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectFormatter
@Visitor(value=Formattable.class) public class Formatter
Formats 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.
For example in order to format an object with curly brackets instead of square ones and the whole text on the same line (no indentation), use the following:
Formatters are not synchronized. It is recommended to create separate formatter instances for each thread. If multiple threads access a formatter concurrently, it must be synchronized externally.Formatter formatter = new Formatter(Symbols.CURLY_BRACKETS, null, WKTFormat.SINGLE_LINE); formatter.append(theObject); String wkt = formatter.toString(); // Following is needed only if you want to reuse // the formatter again for other objects. formatter.clear();
| referencing/geotk-referencing (download) | View source code for this class |
| Constructor Summary | |
|---|---|
Formatter()
Creates a new instance of the formatter with the default symbols, no syntax coloring and the default indentation. |
|
Formatter(int indentation)
Creates a new instance of the formatter with the default symbols, no syntax coloring and the given indentation. |
|
Formatter(Symbols symbols,
Colors colors,
int indentation)
Creates a new instance of the formatter with the specified indentation. |
|
| Method Summary | |
|---|---|
void |
append(CodeList<?> code)
Appends a code list. |
void |
append(double number)
Appends a floating point number. |
void |
append(Formattable formattable)
Appends the given Formattable object. |
void |
append(GeneralParameterValue parameter)
Appends a parameter in WKT form. |
void |
append(IdentifiedObject info)
Appends the specified OpenGIS's IdentifiedObject object. |
void |
append(long number)
Appends an integer number. |
void |
append(MathTransform transform)
Appends the specified math transform. |
void |
append(String text)
Appends a character string. |
void |
append(Unit<?> unit)
Appends a unit in WKT form. |
void |
clear()
Clears this formatter. |
Unit<Angle> |
getAngularUnit()
The angular unit for formatting measures, or null for the "natural" unit of each WKT
element. |
Convention |
getConvention()
Returns the convention to use for formatting the WKT. |
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. |
void |
setAngularUnit(Unit<Angle> unit)
Sets the angular unit for formatting measures. |
void |
setInvalidWKT(Class<?> unformattable)
Set a flag marking the current WKT as not strictly compliant to the WKT specification. |
void |
setLinearUnit(Unit<Length> unit)
Sets the unit for formatting linear measures. |
String |
toString()
Returns the WKT in its current state. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Formatter()
public Formatter(int indentation)
indentation - The amount of spaces to use in indentation for WKT formatting,
or -1 for formatting the
whole WKT on a single line.
public Formatter(Symbols symbols,
Colors colors,
int indentation)
symbols - The symbols.colors - The syntax coloring, or null if none.indentation - The amount of spaces to use in indentation for WKT formatting,
or -1 for formatting the
whole WKT on a single line.| Method Detail |
|---|
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 append to the WKT.public void append(GeneralParameterValue parameter)
parameter - The parameter to append to the WKT.public void append(long number)
number - The integer to append to the WKT.public void append(double number)
number - The floating point value to append to the WKT.public void append(Unit<?> unit)
append(SI.KILO(SI.METRE))
will append "UNIT["km", 1000]" to the WKT.
unit - The unit to append to the WKT.public void append(String text)
text - The string to format to the WKT.public Identifier getIdentifier(IdentifiedObject info)
null.
info - The object to looks for a preferred identifier.
null if none.public String getName(IdentifiedObject info)
The preferred authority can be set by the WKTFormat.setAuthority(Citation) method.
This is not necessarily the authority of the given object name.
Example: The EPSG name of the EPSG:6326 datum is "World Geodetic System
1984". However if the preferred authority is OGC (which is the case by default), then
this method usually returns "WGS84" (the exact string to be returned depends on
the list of declared aliases).
info - The object to looks for a preferred name.
null if the given object has no name.WKTFormat.getAuthority(),
IdentifiedObjects.getName(IdentifiedObject, Citation)public Unit<Length> getLinearUnit()
null for the "natural" unit of each
WKT element.
null.
public void setLinearUnit(Unit<Length> unit)
throws IllegalArgumentException
unit - The new unit, or null.
IllegalArgumentException - If the given unit is not null and not a
linear unit.public Unit<Angle> getAngularUnit()
null for the "natural" unit of each WKT
element. This value is set for example when parsing the "GEOGCS" element, in which
case the enclosed "PRIMEM" element shall use the unit of the enclosing "GEOGCS".
null.
public void setAngularUnit(Unit<Angle> unit)
throws IllegalArgumentException
unit - The new unit, or null.
IllegalArgumentException - If the given unit is not null and not an
angular unit.public Convention getConvention()
OGC. A different convention will usually result in different
parameter names, but may also change the WKT syntax.
null).WKTFormat.setConvention(Convention),
FormattableObject.toWKT(Convention, int)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-dependent.
For example FormattableObject.toString() will accepts loose WKT formatting and ignore
this flag, while FormattableObject.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)
FormattableObject.formatWKT(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()
toString in class Objectpublic void clear()
Formatter object is ready for formatting
a new object.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||