public class WKTFormat extends CompoundFormat<Object>
Parser
and Formatter
,
to be used by 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
#definitions().put(key,value)
method.
After definitions have been added, any call to a parsing method will replace all occurrences
of a short name by the associated long string.
The short names must comply with the rules of Java identifiers. It is recommended, but not
required, to prefix the names by some symbol like "$"
in order to avoid ambiguity.
Note however that this class doesn't replace occurrences between quoted text, so string
expansion still relatively safe even when used with non-prefixed identifiers.
$WGS84
substring which appear in the argument given to the
parseObject(…)
method will be expanded into the full GEOGCS["WGS84", …]
string
before the parsing proceed.
#definitions().put("$WGS84", "GEOGCS[\"WGS84\", DATUM[
…etc…]]);
…etc…
Object crs = parseObject("PROJCS[\"Mercator_1SP\", $WGS84, PROJECTION[]]");
WKTFormat
s are not synchronized. It is recommended to create separated format instances for each thread.
If multiple threads access a 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 |
---|---|
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.
|
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.
|
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.
|
Class<Object> |
getValueType()
Returns the type of objects formatted by this class.
|
String |
getWarning()
If a warning occurred during the last WKT formatting, returns
the warning.
|
boolean |
isNonAsciiAllowed()
Returns whether non-ASCII characters are preserved.
|
Object |
parse(CharSequence text,
ParsePosition position)
Not yet supported.
|
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.
|
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 |
setNameAuthority(Citation authority)
Sets the preferred authority for choosing the projection and parameter names.
|
void |
setNonAsciiAllowed(boolean allowed)
Sets whether non-ASCII characters shall be preserved.
|
void |
setSymbols(Symbols symbols)
Sets the symbols used for parsing and formatting 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 Symbols getSymbols()
public void setSymbols(Symbols symbols)
symbols
- The new set of symbols to use for parsing and formatting WKT.public boolean isNonAsciiAllowed()
false
,
which causes replacements like "é" → "e" in all elements except ElementKind.REMARKS
.
This value is always true
when the WKT convention
is set to Convention.INTERNAL
.
public void setNonAsciiAllowed(boolean allowed)
false
,
which causes replacements like "é" → "e" in all elements except ElementKind.REMARKS
.
Setting this property to true
will disable such replacements.allowed
- Whether non-ASCII characters shall be preserved.public KeywordCase getKeywordCase()
public void setKeywordCase(KeywordCase keywordCase)
keywordCase
- The case 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 |
explicitly set
, then this
method returns the default authority for the current convention.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.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 Object parse(CharSequence text, ParsePosition position)
parse
in class CompoundFormat<Object>
text
- The text to parse.position
- The index of the first character to parse.null
in case of failure.public void format(Object object, Appendable toAppendTo) throws IOException
FormattableObject
, IdentifiedObject
,
MathTransform
,
Matrix
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
.getWarning()
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 String getWarning()
null
. The warning is cleared every time a new object is formatted.null
if none.public WKTFormat clone()
clone
in class CompoundFormat<Object>
Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.