public class WKTFormat extends CompoundFormat<Object>
Parser
and Formatter
,
used by the parse(…)
and format(…)
methods respectively.
WKTFormat
objects allow the following configuration:
Formatter.getNameAuthority()
for more information).WKTFormat
provides a mechanism for performing string substitutions before the parsing take place.
Long strings can be assigned short names by calls to the addFragment(String, String)
method.
After fragments have been added, any call to a parsing method will replace all occurrences (except in
quoted text) of tokens like $foo
by the WKT fragment named "foo".
$WGS84
substring which appear in the argument given to the
parseObject(…)
method will be expanded into the full GeodeticCRS[“WGS84”, …]
string before the parsing proceed.
Note that the parsing of WKT fragment does not always produce the same object. In particular, the default linear and angular units depend on the context in which the WKT fragment appears.addFragment("deg", "AngleUnit[“degree”, 0.0174532925199433]");
…etc…
addFragment("lat", "Axis[“Latitude”, NORTH, $deg]");
addFragment("lon", "Axis[“Longitude”, EAST, $deg]");
addFragment("MyBaseCRS", "GeodeticCRS[“WGS84”, Datum[], CS[
…etc…], $lat, $lon]");
…etc…
Object crs = parseObject("ProjectedCRS[“Mercator_1SP”, $MyBaseCRS,]");
WKTFormat
are not guaranteed to be identical after parsing.
Some metadata may be lost or altered, but the coordinate operations between two CRS should produce
the same numerical results provided that the two CRS were formatted independently (do not rely on
GeneralDerivedCRS.getConversionFromBase()
for instance).WKTFormat
concurrently, it must be synchronized externally.Defined in the sis-metadata
module
Format.Field
Modifier and Type | Field and Description |
---|---|
static int |
SINGLE_LINE
The indentation value to give to the
setIndentation(int)
method for formatting the complete object on a single line. |
Constructor and Description |
---|
WKTFormat(Locale locale,
TimeZone timezone)
Creates a format for the given locale and timezone.
|
Modifier and Type | Method and Description |
---|---|
void |
addFragment(String name,
String wkt)
Adds a fragment of Well Know Text (WKT).
|
WKTFormat |
clone()
Returns a clone of this format.
|
protected Format |
createFormat(Class<?> valueType)
Creates a new format to use for parsing and formatting values of the given type.
|
void |
format(Object object,
Appendable toAppendTo)
Formats the specified object as a Well Know Text.
|
Colors |
getColors()
Returns the colors to use for syntax coloring, or
null if none. |
Convention |
getConvention()
Returns the convention for parsing and formatting WKT elements.
|
<T extends Factory> |
getFactory(Class<T> type)
Returns one of the factories used by this
WKTFormat for parsing WKT. |
Set<String> |
getFragmentNames()
Returns the name of all WKT fragments known to this
WKTFormat . |
int |
getIndentation()
Returns the current indentation to be used for formatting objects.
|
KeywordCase |
getKeywordCase()
Returns whether WKT keywords should be written with upper cases or camel cases.
|
KeywordStyle |
getKeywordStyle()
Returns whether to use short or long WKT keywords.
|
Locale |
getLocale(Locale.Category category)
Returns the locale for the given category.
|
Citation |
getNameAuthority()
Returns the preferred authority to look for when fetching identified object names and identifiers.
|
Symbols |
getSymbols()
Returns the symbols used for parsing and formatting WKT.
|
Transliterator |
getTransliterator()
Returns a mapper between Java character sequences and the characters to write in WKT.
|
Class<Object> |
getValueType()
Returns the type of objects formatted by this class.
|
Warnings |
getWarnings()
If warnings occurred during the last WKT parsing or
formatting, returns the warnings.
|
Object |
parse(CharSequence wkt,
ParsePosition pos)
Creates an object from the given character sequence.
|
void |
setColors(Colors colors)
Sets the colors to use for syntax coloring.
|
void |
setConvention(Convention convention)
Sets the convention for parsing and formatting WKT elements.
|
<T extends Factory> |
setFactory(Class<T> type,
T factory)
Sets one of the factories to be used by this
WKTFormat for parsing WKT. |
void |
setIndentation(int indentation)
Sets a new indentation to be used for formatting objects.
|
void |
setKeywordCase(KeywordCase keywordCase)
Sets whether WKT keywords should be written with upper cases or camel cases.
|
void |
setKeywordStyle(KeywordStyle keywordStyle)
Sets whether to use short or long WKT keywords.
|
void |
setNameAuthority(Citation authority)
Sets the preferred authority for choosing the projection and parameter names.
|
void |
setSymbols(Symbols symbols)
Sets the symbols used for parsing and formatting WKT.
|
void |
setTransliterator(Transliterator transliterator)
Sets the mapper between Java character sequences and the characters to write in WKT.
|
format, getFormat, getLocale, getTimeZone, parseObject, parseObject
format, formatToCharacterIterator
public static final int SINGLE_LINE
setIndentation(int)
method for formatting the complete object on a single line.public WKTFormat(Locale locale, TimeZone timezone)
InternationalString
localization; this is not the locale for number format.locale
- the locale for the new Format
, or null
for Locale.ROOT
.timezone
- the timezone, or null
for UTC.public Locale getLocale(Locale.Category category)
Locale.Category.FORMAT
: the value of Symbols.getLocale()
,
normally fixed to Locale.ROOT
, used for number formatting.Locale.Category.DISPLAY
: the locale
given at construction time,
used for InternationalString
localization.getLocale
in class CompoundFormat<Object>
category
- the category for which a locale is desired.null
).public Symbols getSymbols()
public void setSymbols(Symbols symbols)
symbols
- the new set of symbols to use for parsing and formatting WKT.public Transliterator getTransliterator()
Transliterator.DEFAULT
for performing replacements like "é" → "e"
in all WKT elements except REMARKS["…"]
.Transliterator.IDENTITY
for preserving non-ASCII characters.public void setTransliterator(Transliterator transliterator)
If this method is never invoked, or if this method is invoked with a null
value,
then the default mapper is Transliterator.DEFAULT
except for WKT formatted according
the internal convention.
transliterator
- the new mapper to use, or null
for restoring the default value.public KeywordCase getKeywordCase()
public void setKeywordCase(KeywordCase keywordCase)
keywordCase
- the case to use for formatting keywords.public KeywordStyle getKeywordStyle()
public void setKeywordStyle(KeywordStyle keywordStyle)
keywordStyle
- the style to use for formatting keywords.public Colors getColors()
null
if none.
By default there is no syntax coloring.null
if none.public void setColors(Colors colors)
Newly created WKTFormat
s have no syntax coloring. If a non-null argument like
Colors.DEFAULT
is given to this method, then the format(…)
method tries to highlight most of the elements that are relevant to
Utilities.equalsIgnoreMetadata(Object, Object)
.
colors
- the colors for syntax coloring, or null
if none.public Convention getConvention()
Convention.WKT2
.null
).public void setConvention(Convention convention)
convention
- the new convention to use for parsing and formatting WKT elements.public Citation getNameAuthority()
Authority | Projection name |
---|---|
EPSG | Mercator (variant A) |
OGC | Mercator_1SP |
GEOTIFF | CT_Mercator |
Formatter.getNameAuthority()
public void setNameAuthority(Citation authority)
null
value
restore the default behavior.authority
- the new authority, or null
for inferring it from the convention.Formatter.getNameAuthority()
public int getIndentation()
public void setIndentation(int indentation)
indentation
- the new indentation to use.OptionKey.INDENTATION
public <T extends Factory> T getFactory(Class<T> type)
WKTFormat
for parsing WKT.
The given type
argument can be one of the following values:
CRSFactory.class
CSFactory.class
DatumFactory.class
MathTransformFactory.class
CoordinateOperationFactory.class
T
- the compile-time type of the type
argument.type
- the factory type.WKTFormat
for the given type.IllegalArgumentException
- if the type
argument is not one of the valid values.public <T extends Factory> void setFactory(Class<T> type, T factory)
WKTFormat
for parsing WKT.
The given type
argument can be one of the following values:
CRSFactory.class
CSFactory.class
DatumFactory.class
MathTransformFactory.class
CoordinateOperationFactory.class
Serializable
. The factories used by WKTFormat
instances after deserialization
are the default ones.T
- the compile-time type of the type
argument.type
- the factory type.factory
- the factory to be used by this WKTFormat
for the given type.IllegalArgumentException
- if the type
argument is not one of the valid values.public final Class<Object> getValueType()
Object.class
since it is the only common parent to all object types accepted by this formatter.getValueType
in class CompoundFormat<Object>
Object.class
public Set<String> getFragmentNames()
WKTFormat
.
The returned collection is initially empty.
WKT fragments can be added by call to addFragment(String, String)
.
The returned collection is modifiable. In particular, a call to Set.clear()
removes all fragments from this WKTFormat
.
WKTFormat
.public void addFragment(String name, String wkt) throws IllegalArgumentException, ParseException
wkt
argument given to this method
can contains itself other fragments specified in some previous calls to this method.
addFragment("MyEllipsoid", "Ellipsoid[“Bessel 1841”, 6377397.155, 299.1528128, ID[“EPSG”,“7004”]]");Then other WKT strings parsed by this
WKTFormat
instance can refer to the above fragment as below
(WKT after the ellipsoid omitted for brevity):
Object crs = parseObject("GeodeticCRS[“Tokyo”, Datum[“Tokyo”, $MyEllipsoid], …]");
getFragmentNames().remove(name)
.name
- the name to assign to the WKT fragment. Identifiers are case-sensitive.wkt
- the Well Know Text (WKT) fragment represented by the given identifier.IllegalArgumentException
- if the name is invalid or if a fragment is already present for that name.ParseException
- if an error occurred while parsing the given WKT.public Object parse(CharSequence wkt, ParsePosition pos) throws ParseException
pos
argument.
After successful parsing, ParsePosition.getIndex()
gives the position after the last parsed character.
In case of error, ParseException.getErrorOffset()
gives the position of the first illegal character.parse
in class CompoundFormat<Object>
wkt
- the character sequence for the object to parse.pos
- the position where to start the parsing.null
).ParseException
- if an error occurred while parsing the WKT.public void format(Object object, Appendable toAppendTo) throws IOException
FormattableObject
, IdentifiedObject
,
MathTransform
,
GeographicBoundingBox
,
VerticalExtent
,
TemporalExtent
and Unit
.format
in class CompoundFormat<Object>
object
- the object to format.toAppendTo
- where the text is to be appended.IOException
- if an error occurred while writing to toAppendTo
.FormattableObject.toWKT()
protected Format createFormat(Class<?> valueType)
valueType
can be any types declared in the
parent class.createFormat
in class CompoundFormat<Object>
valueType
- the base type of values to parse or format.null
if none.public Warnings getWarnings()
null
.
The warnings are cleared every time a new object is parsed or formatted.null
if none.public WKTFormat clone()
clone
in class CompoundFormat<Object>
Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.