public class CoordinateFormat extends CompoundFormat<DirectPosition>
AngleFormat
.DateFormat
.NumberFormat
followed by the unit symbol
formatted by UnitFormat
.applyPattern(Class, String)
public method,
or by overriding the CompoundFormat.createFormat(Class)
protected method.
This format does not transform the given coordinates in a unique CRS. If the coordinates need to be formatted in a specific CRS, then the caller should transform the position before to format it.
AngleFormat
,
UnitFormat
,
GeneralDirectPosition
,
Serialized FormDefined in the sis-referencing
module
Format.Field
Constructor and Description |
---|
CoordinateFormat()
Constructs a new coordinate format with default locale and timezone.
|
CoordinateFormat(Locale locale,
TimeZone timezone)
Constructs a new coordinate format for the specified locale and timezone.
|
Modifier and Type | Method and Description |
---|---|
boolean |
applyPattern(Class<?> valueType,
String pattern)
Sets the pattern for number, angle or date fields.
|
CoordinateFormat |
clone()
Returns a clone of this format.
|
String |
format(DirectPosition position)
Formats the given coordinate.
|
void |
format(DirectPosition position,
Appendable toAppendTo)
Formats the given coordinate and appends the resulting text to the given stream or buffer.
|
CoordinateReferenceSystem |
getDefaultCRS()
Returns the coordinate reference system to use if no CRS is explicitely associated to a given
DirectPosition . |
String |
getPattern(Class<?> valueType)
Returns the pattern for number, angle or date fields.
|
String |
getSeparator()
Returns the separator between each coordinate (number, angle or date).
|
Class<DirectPosition> |
getValueType()
Returns the base type of values parsed and formatted by this
Format instance. |
DirectPosition |
parse(CharSequence text,
ParsePosition pos)
Parses a coordinate from the given character sequence.
|
void |
setDefaultCRS(CoordinateReferenceSystem crs)
Sets the coordinate reference system to use if no CRS is explicitely associated to a given
DirectPosition . |
void |
setSeparator(String separator)
Sets the separator between each coordinate.
|
createFormat, format, getFormat, getLocale, getLocale, getTimeZone, parseObject, parseObject
format, formatToCharacterIterator
public CoordinateFormat()
public String getSeparator()
public void setSeparator(String separator)
separator
- the new coordinate separator.public CoordinateReferenceSystem getDefaultCRS()
DirectPosition
.null
if none.public void setDefaultCRS(CoordinateReferenceSystem crs)
DirectPosition
.
This CRS is only a default; positions given in another CRS are not automatically transformed to
that CRS before formatting.crs
- the default coordinate reference system, or null
if none.public String getPattern(Class<?> valueType)
valueType
should be
Number.class
, Angle.class
, Date.class
or a sub-type of the above.
This method may return null
if the underlying format can not provide a pattern.
Value type | Base format class | Format with pattern |
---|---|---|
Number | NumberFormat | DecimalFormat |
Angle | AngleFormat | AngleFormat |
Date | DateFormat | SimpleDateFormat |
valueType
- the base type of ordinate values to parse and format:
Number.class
, Angle.class
or Date.class
.null
if not applicable.CompoundFormat.getFormat(Class)
public boolean applyPattern(Class<?> valueType, String pattern)
valueType
argument:
valueType
is Number.class
, then the pattern syntax shall be as described in the
DecimalFormat
class. This pattern may be used for any ordinate to be formatted as plain number,
for example in Cartesian coordinate system.valueType
is Angle.class
, then the pattern syntax shall be as described in the
AngleFormat
class. This pattern may be used for any ordinate to be formatted as latitude or longitude,
for example in ellipsoidal coordinate system.valueType
is Date.class
, then the pattern syntax shall be as described in the
SimpleDateFormat
class. This pattern may be used for any ordinate to be formatted as date and time,
for example in time coordinate system.valueType
- the base type of ordinate values to parse and format:
Number.class
, Angle.class
or Date.class
.pattern
- the pattern as specified in DecimalFormat
, AngleFormat
or SimpleDateFormat
javadoc.true
if the pattern has been applied, or false
if valueType
does not
specify a known type or if the format associated to that type does not support patterns.IllegalArgumentException
- if the given pattern is invalid.public final Class<DirectPosition> getValueType()
Format
instance.getValueType
in class CompoundFormat<DirectPosition>
DirectPosition.class
.public String format(DirectPosition position)
position
- the coordinate to format.public void format(DirectPosition position, Appendable toAppendTo) throws IOException
format
in class CompoundFormat<DirectPosition>
position
- the coordinate to format.toAppendTo
- where the text is to be appended.IOException
- if an error occurred while writing to the given appendable.public DirectPosition parse(CharSequence text, ParsePosition pos) throws ParseException
pos
argument.
If parsing succeeds, then the pos
index is updated to the index after the last ordinate value and
the parsed coordinate is returned. Otherwise (if parsing fails), the pos
index is left unchanged,
the pos
error index is set to the index of the first
unparsable character and an exception is thrown with a similar error index.parse
in class CompoundFormat<DirectPosition>
text
- the character sequence for the coordinate to parse.pos
- the index where to start the parsing.null
).ParseException
- if an error occurred while parsing the coordinate.public CoordinateFormat clone()
clone
in class CompoundFormat<DirectPosition>
Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.