Package org.geotools.referencing.wkt
Class Parser
-
- All Implemented Interfaces:
Serializable,Cloneable
public class Parser extends MathTransformParser
Parser for Well Known Text (WKT). This parser can parse math transform objects as well, which is part of the WKT'sFITTED_CSelement.- Since:
- 2.0
- Author:
- Remi Eve, Martin Desruisseaux (IRD)
- See Also:
- Well Know Text specification, OGC WKT Coordinate System Issues, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class Format
Format.Field
-
-
Field Summary
Fields Modifier and Type Field Description protected CRSFactorycrsFactoryThe factory to use for creating coordinate reference systems.protected CSFactorycsFactoryThe factory to use for creating coordinate systems.protected DatumFactorydatumFactoryThe factory to use for creating datum.-
Fields inherited from class MathTransformParser
mtFactory
-
-
Constructor Summary
Constructors Constructor Description Parser()Constructs a parser using the default set of symbols and factories.Parser(Symbols symbols)Constructs a parser for the specified set of symbols using default factories.Parser(Symbols symbols, DatumFactory datumFactory, CSFactory csFactory, CRSFactory crsFactory, MathTransformFactory mtFactory)Constructs a parser for the specified set of symbols using the specified factories.Parser(Symbols symbols, ReferencingFactoryContainer factories)Constructs a parser for the specified set of symbols using the specified set of factories.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<String,Object>alterProperties(Map<String,Object> properties)Returns the properties to be given to the parsed object.static Class<?>getClassOf(String element)Returns the class of the specified WKT element.static StringgetNameOf(Class<?> type)Returns the WKT name of the specified object type.static voidmain(String... args)Read WKT strings from the standard input stream and reformat them to the standard output stream.protected Objectparse(Element element)Parses the next element in the specified Well Know Text (WKT) tree.CoordinateReferenceSystemparseCoordinateReferenceSystem(String text)Parses a coordinate reference system element.-
Methods inherited from class MathTransformParser
parseMathTransform
-
Methods inherited from class AbstractParser
format, getAuthority, getTree, getWarning, isColorEnabled, parseObject, parseObject, reformat, setAuthority, setColorEnabled
-
Methods inherited from class Format
clone, format, formatToCharacterIterator
-
-
-
-
Field Detail
-
datumFactory
protected final DatumFactory datumFactory
The factory to use for creating datum.
-
csFactory
protected final CSFactory csFactory
The factory to use for creating coordinate systems.
-
crsFactory
protected final CRSFactory crsFactory
The factory to use for creating coordinate reference systems.
-
-
Constructor Detail
-
Parser
public Parser()
Constructs a parser using the default set of symbols and factories.
-
Parser
public Parser(Symbols symbols)
Constructs a parser for the specified set of symbols using default factories.- Parameters:
symbols- The symbols for parsing and formatting numbers.
-
Parser
public Parser(Symbols symbols, ReferencingFactoryContainer factories)
Constructs a parser for the specified set of symbols using the specified set of factories.- Parameters:
symbols- The symbols for parsing and formatting numbers.factories- The factories to use.
-
Parser
public Parser(Symbols symbols, DatumFactory datumFactory, CSFactory csFactory, CRSFactory crsFactory, MathTransformFactory mtFactory)
Constructs a parser for the specified set of symbols using the specified factories.- Parameters:
symbols- The symbols for parsing and formatting numbers.datumFactory- The factory to use for creating datum.csFactory- The factory to use for creating coordinate systems.crsFactory- The factory to use for creating coordinate reference systems.mtFactory- The factory to use for creating math transform objects.
-
-
Method Detail
-
parseCoordinateReferenceSystem
public CoordinateReferenceSystem parseCoordinateReferenceSystem(String text) throws ParseException
Parses a coordinate reference system element.- Parameters:
text- The text to be parsed.- Returns:
- The coordinate reference system.
- Throws:
ParseException- if the string can't be parsed.
-
parse
protected Object parse(Element element) throws ParseException
Parses the next element in the specified Well Know Text (WKT) tree.- Overrides:
parsein classMathTransformParser- Parameters:
element- The element to be parsed.- Returns:
- The object.
- Throws:
ParseException- if the element can't be parsed.
-
alterProperties
protected Map<String,Object> alterProperties(Map<String,Object> properties)
Returns the properties to be given to the parsed object. This method is invoked automatically by the parser for the root element only. This method expect on input the properties parsed from theAUTHORITYelement, and returns on output the properties to give to the object to be created. The default implementation returns thepropertiesmap unchanged. Subclasses may override this method in order to add or change properties.Example: if a subclass want to add automatically an authority code when no
AUTHORITYelement was explicitly set in the WKT, then it may test for theIdentifiedObject.IDENTIFIERS_KEYkey and add automatically an entry if this key was missing.- Parameters:
properties- The properties parsed from the WKT file. Entries can be added, removed or modified directly in this map.- Returns:
- The properties to be given to the parsed object. This is usually
properties(maybe after modifications), but could also be a new map. - Since:
- 2.3
-
getClassOf
public static Class<?> getClassOf(String element)
Returns the class of the specified WKT element. For example this method returnsProjectedCRS.classfor element "PROJCS".- Parameters:
element- The WKT element name.- Returns:
- The GeoAPI class of the specified element, or
nullif unknow.
-
getNameOf
public static String getNameOf(Class<?> type)
Returns the WKT name of the specified object type. For example this method returns "PROJCS" for typeProjectedCRS.class.- Parameters:
type- The GeoAPI class of the specified element.- Returns:
- The WKT element name, or
nullif unknow. - Since:
- 2.4
-
main
public static void main(String... args)
Read WKT strings from the standard input stream and reformat them to the standard output stream. The input is read until it reach the end-of-file ([Ctrl-Z]if reading from the keyboard), or until an unparsable WKT has been hit. Optional arguments are:-authority<name>The authority to prefer when choosing WKT entities names. -indentation<value>Set the indentation (0 for output on a single line) -encoding<code>Set the character encoding -locale<language>Set the language for the output (e.g. "fr" for French) - Parameters:
args- The command line arguments.
-
-