Package org.geotools.referencing.wkt
Class Formatter
- Object
- 
- Formatter
 
- 
 public class Formatter extends Object FormatFormattableobjects 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. - Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD)
- See Also:
- Well Know Text specification, OGC WKT Coordinate System Issues
 
- 
- 
Constructor SummaryConstructors Constructor 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.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(double number)Append a floating point number.voidappend(int number)Append an integer number.voidappend(String text)Append a character string.voidappend(Unit<?> unit)Appends a unit in WKT form.voidappend(GeneralParameterValue parameter)Append a parameter in WKT form.voidappend(IdentifiedObject info)Append the specified OpenGIS'sIdentifiedObjectobject.voidappend(MathTransform transform)Append the specified math transform.voidappend(CodeList code)Append a code list to the WKT.voidappend(Formattable formattable)Append the specifiedFormattableobject.voidclear()Clear this formatter.Unit<Angle>getAngularUnit()The angular unit for formatting measures, ornullfor the "natural" unit of each WKT element.CitationgetAuthority()IdentifiergetIdentifier(IdentifiedObject info)Returns the preferred identifier for the specified object.Unit<Length>getLinearUnit()The linear unit for formatting measures, ornullfor the "natural" unit of each WKT element.StringgetName(IdentifiedObject info)Returns the preferred name for the specified object.booleanisInvalidWKT()Returnstrueif the WKT in this formatter is not strictly compliant to the WKT specification.static voidmain(String... args)Set the preferred indentation from the command line.voidsetAngularUnit(Unit<Angle> unit)Set the angular unit for formatting measures.voidsetAuthority(Citation authority)voidsetInvalidWKT(Class<?> unformattable)Set a flag marking the current WKT as not strictly compliant to the WKT specification.voidsetLinearUnit(Unit<Length> unit)Set the unit for formatting linear measures.StringtoString()Returns the WKT in its current state.
 
- 
- 
- 
Constructor Detail- 
Formatterpublic Formatter() Creates a new instance of the formatter with the default symbols.
 - 
Formatterpublic Formatter(Symbols symbols) Creates a new instance of the formatter. The whole WKT will be formatted on a single line.- Parameters:
- symbols- The symbols.
 
 - 
Formatterpublic Formatter(Symbols symbols, int indentation) Creates a new instance of the formatter with the specified indentation width. The WKT will be formatted on many lines, and the indentation width will have the value specified to this constructor. If the specified indentation isFormattableObject#SINGLE_LINE, then the whole WKT will be formatted on a single line.- Parameters:
- symbols- The symbols.
- indentation- The amount of spaces to use in indentation. Typical values are 2 or 4.
 
 
- 
 - 
Method Detail- 
getAuthoritypublic Citation getAuthority() 
 - 
setAuthoritypublic void setAuthority(Citation authority) 
 - 
appendpublic void append(Formattable formattable) Append the specifiedFormattableobject. This method will automatically append the keyword (e.g."GEOCS"), the name and the authority code, and will invokesformattable.formatWKT(this)for completing the inner part of the WKT.- Parameters:
- formattable- The formattable object to append to the WKT.
 
 - 
appendpublic void append(IdentifiedObject info) Append the specified OpenGIS'sIdentifiedObjectobject.- Parameters:
- info- The info object to append to the WKT.
 
 - 
appendpublic void append(MathTransform transform) Append the specified math transform.- Parameters:
- transform- The transform object to append to the WKT.
 
 - 
appendpublic void append(CodeList code) Append a code list to the WKT.- Parameters:
- code- The code list to format.
 
 - 
appendpublic void append(GeneralParameterValue parameter) Append a parameter in WKT form. If the supplied parameter is actually a parameter group, all parameters will be inlined.- Parameters:
- parameter- The parameter to format.
 
 - 
appendpublic void append(int number) Append an integer number. A comma (or any other element separator) will be written before the number if needed.- Parameters:
- number- The integer to format.
 
 - 
appendpublic void append(double number) Append a floating point number. A comma (or any other element separator) will be written before the number if needed.- Parameters:
- number- The floating point value to format.
 
 - 
appendpublic void append(Unit<?> unit) Appends a unit in WKT form. For example,append(SI.KILOMETER)can append "UNIT["km", 1000]" to the WKT.- Parameters:
- unit- The unit to append.
- Throws:
- IllegalArgumentException- if the provided unit is not
 
 - 
appendpublic void append(String text) Append a character string. The string will be written between quotes. A comma (or any other element separator) will be written before the string if needed.- Parameters:
- text- The string to format.
 
 - 
getIdentifierpublic Identifier getIdentifier(IdentifiedObject info) Returns the preferred identifier for the specified object. If the specified object contains an identifier from the preferred authority (usually Open Geospatial), then this identifier is returned. Otherwise, the first identifier is returned. If the specified object contains no identifier, then this method returnsnull.- Parameters:
- info- The object to looks for a preferred identifier.
- Returns:
- The preferred identifier, or nullif none.
- Since:
- 2.3
 
 - 
getNamepublic String getName(IdentifiedObject info) Returns the preferred name for the specified object. If the specified object contains a name from the preferred authority (usually Open Geospatial), then this name is returned. Otherwise, the first name found is returned.- Parameters:
- info- The object to looks for a preferred name.
- Returns:
- The preferred name.
 
 - 
getLinearUnitpublic Unit<Length> getLinearUnit() The linear unit for formatting measures, ornullfor the "natural" unit of each WKT element.- Returns:
- The unit for measure. Default value is null.
 
 - 
setLinearUnitpublic void setLinearUnit(Unit<Length> unit) Set the unit for formatting linear measures.- Parameters:
- unit- The new unit, or- null.
 
 - 
getAngularUnitpublic Unit<Angle> getAngularUnit() The angular unit for formatting measures, ornullfor 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.- Returns:
- The unit for measure. Default value is null.
 
 - 
setAngularUnitpublic void setAngularUnit(Unit<Angle> unit) Set the angular unit for formatting measures.- Parameters:
- unit- The new unit, or- null.
 
 - 
isInvalidWKTpublic boolean isInvalidWKT() Returnstrueif the WKT in this formatter is not strictly compliant to the WKT specification. This method returnstrueifsetInvalidWKT(java.lang.Class<?>)has been invoked at least once. The action to take regarding invalid WKT is caller-dependant. For exampleFormattable.toString()will accepts loose WKT formatting and ignore this flag, whileFormattable.toWKT()requires strict WKT formatting and will thrown an exception if this flag is set.- Returns:
- trueif the WKT is invalid.
 
 - 
setInvalidWKTpublic void setInvalidWKT(Class<?> unformattable) Set a flag marking the current WKT as not strictly compliant to the WKT specification. This method is invoked byFormattable.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 testsisInvalidWKT()later for checking WKT validity.- Parameters:
- unformattable- The type of the component that can't be formatted, for example- EngineeringCRS.
- Since:
- 2.4
- See Also:
- UnformattableObjectException.getUnformattableClass()
 
 - 
toStringpublic String toString() Returns the WKT in its current state.
 - 
clearpublic void clear() Clear this formatter. All properties (including unit and WKT validity flag are reset to their default value. After this method call, thisFormatterobject is ready for formatting a new object.
 - 
mainpublic static void main(String... args) Set the preferred indentation from the command line. This indentation is used byFormattable.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>- Parameters:
- args- The command-line arguments.
 
 
- 
 
-