- All Implemented Interfaces:
Serializable
,Cloneable
,Localized
- Coordinate values in angular units are formatted as angles using
AngleFormat
. - Coordinate values in temporal units are formatted as dates using
DateFormat
. - Other values are formatted as numbers using
NumberFormat
followed by the unit symbol formatted byUnitFormat
.
applyPattern(Class, String)
public method,
or by overriding the createFormat(Class)
protected method.
Coordinate reference system
CoordinateFormat
uses the DirectPosition.getCoordinateReferenceSystem()
value for determining
how to format each coordinate value. If the position does not specify a coordinate reference system, then the
default CRS is assumed. If no default CRS has been
specified, then all coordinates are formatted as decimal numbers.
CoordinateFormat
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.
- Since:
- 0.8
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Format
Format.Field
-
Constructor Summary
ConstructorDescriptionConstructs 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. -
Method Summary
Modifier and TypeMethodDescriptionboolean
applyPattern
(Class<?> valueType, String pattern) Sets the pattern for number, angle or date fields.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.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.Returns the coordinate reference system to use if no CRS is explicitly associated to a givenDirectPosition
.Quantity
<?> Returns the current ground accuracy value, ornull
if none.Returns the textual representation of the current ground accuracy.getPattern
(Class<?> valueType) Returns the pattern for number, angle or date fields.double[]
Returns the precisions at which coordinate values are formatted in each dimension.Returns the separator between each coordinate (number, angle or date).final Class
<DirectPosition> Returns the base type of values parsed and formatted by thisFormat
instance.parse
(CharSequence text, ParsePosition pos) Parses a coordinate from the given character sequence.void
Sets the coordinate reference system to use if no CRS is explicitly associated to a givenDirectPosition
.void
setGroundAccuracy
(Quantity<?> accuracy) Specifies an uncertainty to append as "± accuracy" after the coordinate values.void
setGroundPrecision
(Quantity<?> precision) Adjusts the number of fraction digits to show in coordinates for achieving the given precision.void
setPrecisions
(double... precisions) Sets the desired precisions at which to format coordinate values in each dimension.void
setSeparator
(String separator) Sets the separator between each coordinate.Methods inherited from class CompoundFormat
format, getFormat, getLocale, getLocale, getTimeZone, parseObject, parseObject
Methods inherited from class Format
format, formatToCharacterIterator
-
Constructor Details
-
CoordinateFormat
public CoordinateFormat()Constructs a new coordinate format with default locale and timezone. -
CoordinateFormat
Constructs a new coordinate format for the specified locale and timezone.- Parameters:
locale
- the locale for the newFormat
, ornull
forLocale.ROOT
.timezone
- the timezone, ornull
for UTC.
-
-
Method Details
-
getSeparator
Returns the separator between each coordinate (number, angle or date). The default value is a single space.- Returns:
- the current coordinate separator.
-
setSeparator
Sets the separator between each coordinate. The default value is a single space.- Parameters:
separator
- the new coordinate separator.
-
getDefaultCRS
Returns the coordinate reference system to use if no CRS is explicitly associated to a givenDirectPosition
. This CRS determines the type of format to use for each coordinate (number, angle or date) and the number of fraction digits to use for achieving a specified precision on ground.- Returns:
- the default coordinate reference system, or
null
if none.
-
setDefaultCRS
Sets the coordinate reference system to use if no CRS is explicitly associated to a givenDirectPosition
. This CRS is only a default; positions given in another CRS are not automatically transformed to that CRS before formatting.- Parameters:
crs
- the default coordinate reference system, ornull
if none.
-
getPrecisions
public double[] getPrecisions()Returns the precisions at which coordinate values are formatted in each dimension. For example if coordinates in dimension i are formatted with two fraction digits, then the precision reported inprecisions[i]
will be 0.01. If the precision cannot be determined for some dimensions, the corresponding values in the returned array will be 0.The values returned by this method are not necessarily equal to the values specified in the last call to
setPrecisions(double...)
. For example if a precision of 0.03 has been requested for a dimension whose coordinates are formatted as decimal numbers, then the actual precision returned by this method for that dimension will be 0.01.- Returns:
- precision of coordinate values in each dimension (may contain 0 values for unknown precisions).
- Since:
- 1.1
- See Also:
-
setPrecisions
public void setPrecisions(double... precisions) Sets the desired precisions at which to format coordinate values in each dimension. For example ifprecisions[i]
is 0.05, then coordinates in dimension i will be shown with two fraction digits when formatted as decimal numbers, or with "D°MM" pattern when formatted as angles.This precision does not have a direct relationship to the precision on the ground. For example, a precision of 0.01 could be one centimeter or 10 meters, depending if the units of measurement in that dimension is meter or kilometer. For a precision related to the ground, use
setGroundPrecision(Quantity)
instead.If any value in the given array is 0 or
Double.NaN
, then there is a choice: ifsetGroundPrecision(Quantity)
has been invoked, the precision specified to that method will apply (if possible). Otherwise an implementation-specific default precision is used. A typical use case is to usesetGroundPrecision(Quantity)
for specifying an horizontal precision in "real world" units and to use thissetPrecisions(double...)
method for adjusting the precision of the vertical axis only.- Parameters:
precisions
- desired precision at which to format coordinate values in each dimension (may have 0 orDouble.NaN
values for unspecified precisions in some of those dimensions), ornull
for restoring the default values.- Since:
- 1.1
- See Also:
-
setGroundPrecision
Adjusts the number of fraction digits to show in coordinates for achieving the given precision. TheNumberFormat
andAngleFormat
are configured for coordinates expressed in the coordinate reference system of the position to format. The given resolution will be converted to the units used by coordinate system axes. For example if a 10 metres resolution is specified but the default CRS axes use kilometres, then this method converts the resolution to 0.01 kilometre and uses that value for inferring that coordinates should be formatted with 2 fraction digits. If the resolution is specified in an angular units such as degrees, this method uses the ellipsoid authalic radius for computing an equivalent resolution in linear units. For example if the ellipsoid of default CRS is WGS84, then this method considers a resolution of 1 second of angle as equivalent to a resolution of about 31 meters. Conversions work also in the opposite direction (from linear to angular units) and are also used for choosing which angle fields (degrees, minutes or seconds) to show.If both
setPrecisions(double...)
andsetGroundPrecision(Quantity)
are used, then the values specified withsetPrecisions(…)
have precedence and this ground precision is used only as a fallback. A typical use case is to specify the ground precision for horizontal dimensions, then to specify a different precision dz for the vertical axis only withsetPrecisions(NaN, NaN, dz)
.- Parameters:
precision
- the desired precision together with its linear or angular unit.- Since:
- 1.1
- See Also:
-
setGroundAccuracy
Specifies an uncertainty to append as "± accuracy" after the coordinate values. If no precisions have been specified, the accuracy will be always shown. But if precisions have been specified, then the accuracy will be shown only if equals or greater than the precision.- Parameters:
accuracy
- the accuracy to append after the coordinate values, ornull
if none.- Since:
- 1.1
- See Also:
-
getGroundAccuracy
Returns the current ground accuracy value, ornull
if none. This is the value given to the last call tosetGroundAccuracy(Quantity)
.- Returns:
- the current ground accuracy value, or
null
if none. - See Also:
-
getGroundAccuracyText
Returns the textual representation of the current ground accuracy. Example: " ± 3 m" (note the leading space).- Returns:
- textual representation of current ground accuracy.
- See Also:
-
getPattern
Returns the pattern for number, angle or date fields. The givenvalueType
should beNumber.class
,Angle.class
,Date.class
or a sub-type of the above. This method may returnnull
if the underlying format cannot provide a pattern.Pattern availability for type of value Value type Base format class Format with pattern Number
NumberFormat
DecimalFormat
Angle
AngleFormat
AngleFormat
Date
DateFormat
SimpleDateFormat
- Parameters:
valueType
- the base type of coordinate values to parse and format:Number.class
,Angle.class
orDate.class
.- Returns:
- the pattern for fields of the given type, or
null
if not applicable. - See Also:
-
applyPattern
Sets the pattern for number, angle or date fields. The pattern syntax depends on thevalueType
argument:- If
valueType
isNumber.class
, then the pattern syntax shall be as described in theDecimalFormat
class. This pattern may be used for any coordinate to be formatted as plain number, for example in Cartesian coordinate system. - If
valueType
isAngle.class
, then the pattern syntax shall be as described in theAngleFormat
class. This pattern may be used for any coordinate to be formatted as latitude or longitude, for example in ellipsoidal coordinate system. - If
valueType
isDate.class
, then the pattern syntax shall be as described in theSimpleDateFormat
class. This pattern may be used for any coordinate to be formatted as date and time, for example in time coordinate system.
- Parameters:
valueType
- the base type of coordinate values to parse and format:Number.class
,Angle.class
orDate.class
.pattern
- the pattern as specified inDecimalFormat
,AngleFormat
orSimpleDateFormat
javadoc.- Returns:
true
if the pattern has been applied, orfalse
ifvalueType
does not specify a known type or if the format associated to that type does not support patterns.- Throws:
IllegalArgumentException
- if the given pattern is invalid.
- If
-
getValueType
Returns the base type of values parsed and formatted by thisFormat
instance.- Specified by:
getValueType
in classCompoundFormat<DirectPosition>
- Returns:
DirectPosition.class
.
-
createFormat
Creates a new format to use for parsing and formatting values of the given type. This method is invoked byCompoundFormat.getFormat(Class)
the first time that a format is needed for the given type.See super-class for a description of recognized types. This method override uses the short date pattern instead of the (longer) default one.
- Overrides:
createFormat
in classCompoundFormat<DirectPosition>
- Parameters:
valueType
- the base type of values to parse or format.- Returns:
- the format to use for parsing of formatting values of the given type, or
null
if none.
-
format
Formats the given coordinate. The type of each coordinate value (number, angle or date) is determined by the CRS of the given position if such CRS is defined, or from the default CRS otherwise.- Parameters:
position
- the coordinate to format.- Returns:
- the formatted position.
-
format
Formats the given coordinate and appends the resulting text to the given stream or buffer. The type of each coordinate value (number, angle or date) is determined by the CRS of the given position if such CRS is defined, or from the default CRS otherwise.- Specified by:
format
in classCompoundFormat<DirectPosition>
- Parameters:
position
- the coordinate to format.toAppendTo
- where the text is to be appended.- Throws:
IOException
- if an error occurred while writing to the given appendable.ArithmeticException
- if a date value exceed the capacity oflong
type.
-
parse
Parses a coordinate from the given character sequence. This method presumes that the coordinate reference system is the default CRS. The parsing begins at the index given by thepos
argument. If parsing succeeds, then thepos
index is updated to the index after the last coordinate value and the parsed coordinate is returned. Otherwise (if parsing fails), thepos
index is left unchanged, thepos
error index is set to the index of the first unparsable character and an exception is thrown with a similar error index.- Specified by:
parse
in classCompoundFormat<DirectPosition>
- Parameters:
text
- the character sequence for the coordinate to parse.pos
- the index where to start the parsing.- Returns:
- the parsed coordinate (never
null
). - Throws:
ParseException
- if an error occurred while parsing the coordinate.
-
clone
Returns a clone of this format.- Overrides:
clone
in classCompoundFormat<DirectPosition>
- Returns:
- a clone of this format.
-