Class CoordinateFormat
- 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
- Version:
- 1.3
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Desired resolution in a given units, together with methods for converting to the units of a coordinate system axis.Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
Text to append to the coordinate values for giving an indication about accuracy, ornull
if none.private double
Value ofdesiredPrecisions
which causeaccuracyText
to be shown.private static final byte
Constants for thetypes
array.private StringBuffer
Temporary buffer to use if thetoAppendTo
argument given toformat(DirectPosition, Appendable)
is not an instance ofStringBuffer
.private static final byte
Constants for thetypes
array.private static final int
Maximal number of dimensions to use when parsing a coordinate withoutdefaultCRS
.private org.opengis.referencing.crs.CoordinateReferenceSystem
The coordinate reference system to assume if no CRS is attached to the position to format.private double[]
The desired precisions for each coordinate, ornull
if unspecified.private String[]
Directions symbols ("E", "N", "SW", etc.) to append after coordinate values for some dimensions, including leading space.private FieldPosition
Dummy field position.private long[]
The time epochs.private Format[]
The formats to use for formatting each coordinate value, ornull
if not yet computed.private javax.measure.Quantity<?>
The declared accuracy on ground, ornull
if unspecified.private long
The dimensions on whichgroundPrecision
applies, specified as a bitmask.private javax.measure.Quantity<?>
The desired ground precision, ornull
if unspecified.private static final byte
Constants for thetypes
array.private boolean
Whether to append the accuracy after coordinate values.private boolean
Whether thisCoordinateFormat
instance has been configured for the precision and accuracy specified bygroundPrecision
,desiredPrecisions
andgroundAccuracy
.private org.opengis.referencing.crs.CoordinateReferenceSystem
The coordinate reference system of the lastDirectPosition
that we parsed or formatted.private static final byte
Constants for thetypes
array.private static final byte
Constants for thetypes
array.private long
Flags the coordinate values that need to be inverted before to be formatted.private String
The separator without spaces, or an empty string if the separator contains only white spaces.private static final int
Maximal number of characters to convert toString
if the text to parse is not a string instance.private static final Set<javax.measure.Unit<?>>
Units of measurement which are allowed to be automatically scaled to a larger unit.private String
The separator between each coordinate values to be formatted.private static final long
Serial number for cross-version compatibility.private Format[]
The format instances given byCompoundFormat.getFormat(Class)
, to use by default when we have not been able to configure the precision.private static final byte
Constants for thetypes
array.private javax.measure.UnitConverter[]
Conversions from arbitrary units to the unit used by formatter, ornull
if none.private byte[]
The type for each value in theformats
array, ornull
if not yet computed.private javax.measure.Unit<?>[]
The units for each dimension to be formatted as a number with an unit of measurement.private String[]
Units symbols to append after coordinate values for each dimension, including leading space.private String[]
Same asunitSymbols
but without the changes applied bysetPrecisions(double...)
. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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 TypeMethodDescriptionprivate void
applyGroundAccuracy
(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Updates theaccuracyThreshold
for the currentgroundAccuracy
value (which may be null) and the given coordinate reference system.private void
applyGroundPrecision
(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Configures the formats forgroundPrecision
value.boolean
applyPattern
(Class<?> valueType, String pattern) Sets the pattern for number, angle or date fields.private void
applyPrecision
(int dim) Sets the pattern of the format for the specified dimension according the desired precision.clone()
Returns a clone of this format.private void
configure
(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Computes the values of transient fields from the given CRS and configure the format precisions.protected Format
createFormat
(Class<?> valueType) Creates a new format to use for parsing and formatting values of the given type.private void
createFormats
(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Computes the values of transient fields from the given CRS.format
(org.opengis.geometry.DirectPosition position) Formats the given coordinate.void
format
(org.opengis.geometry.DirectPosition position, Appendable toAppendTo) Formats the given coordinate and appends the resulting text to the given stream or buffer.org.opengis.referencing.crs.CoordinateReferenceSystem
Returns the coordinate reference system to use if no CRS is explicitly associated to a givenDirectPosition
.private Format
The default format to use when no CRS or no axis information is available.private Format
getFormatClone
(int dim) Returns a clone of the format at the specified dimension.javax.measure.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<org.opengis.geometry.DirectPosition>
Returns the base type of values parsed and formatted by thisFormat
instance.private boolean
isNegative
(int dimension) Returnstrue
if the value at the given dimension needs to have its sign reversed.private void
negate
(int dimension) Remembers that coordinate values at the given dimension will need to have their sign reverted.org.opengis.geometry.DirectPosition
parse
(CharSequence text, ParsePosition pos) Parses a coordinate from the given character sequence.private void
Invoked on deserialization for restoring some transient fields.private <Q extends javax.measure.Quantity<Q>>
voidscaleUnit
(int i, javax.measure.Unit<Q> unit) Replaces the "m" or "Pa" units of measurement in the given dimension by "km" or "kPa" or other units.private void
setConverter
(int dimension, int i, javax.measure.UnitConverter c) Sets at the given index a conversion from CRS units to units used by this formatter.void
setDefaultCRS
(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Sets the coordinate reference system to use if no CRS is explicitly associated to a givenDirectPosition
.void
setGroundAccuracy
(javax.measure.Quantity<?> accuracy) Specifies an uncertainty to append as "± accuracy" after the coordinate values.void
setGroundPrecision
(javax.measure.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.private static String
symbol
(org.opengis.referencing.cs.AxisDirection direction) Returns the symbol ("E", "N", "SW", etc.) for given axis direction.private static void
unexpectedException
(String method, Exception error) Invoked when an expected error occurred but continuation is still possible.private void
Updates theisAccuracyVisible
flag according current values ofaccuracyText
,accuracyThreshold
anddesiredPrecisions
.Methods inherited from class org.apache.sis.io.CompoundFormat
format, getFormat, getLocale, getLocale, getTimeZone, parseObject, parseObject
Methods inherited from class java.text.Format
format, formatToCharacterIterator
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerial number for cross-version compatibility.- See Also:
-
READ_AHEAD_LIMIT
private static final int READ_AHEAD_LIMITMaximal number of characters to convert toString
if the text to parse is not a string instance. This is an arbitrary limit that may change (or be removed) in any future SIS version.- See Also:
-
DEFAULT_DIMENSION
private static final int DEFAULT_DIMENSIONMaximal number of dimensions to use when parsing a coordinate withoutdefaultCRS
. This is an arbitrary limit that may change (or be removed) in any future SIS version. To avoid this limitation, users are encouraged to specify a default CRS.- See Also:
-
SCALABLES
Units of measurement which are allowed to be automatically scaled to a larger unit. For example if the unit of measurement of an axis is meter but the precision is 1000 metres, thenCoordinateFormat
will automatically uses kilometres units instead of metres. -
separator
The separator between each coordinate values to be formatted. The default value is a EM space space (U+2003).- See Also:
-
parseSeparator
The separator without spaces, or an empty string if the separator contains only white spaces. This is used at parsing time only. -
groundPrecision
private javax.measure.Quantity<?> groundPrecisionThe desired ground precision, ornull
if unspecified. This precision may not apply to all axes. The "ground axes" dimensions are identified by the bits set in thegroundDimensions
bitmask.- See Also:
-
groundAccuracy
private javax.measure.Quantity<?> groundAccuracyThe declared accuracy on ground, ornull
if unspecified. The accuracy applies to the same axes thangroundPrecision
. But contrarily togroundPrecision
, the accuracy does not change the number of fraction digits used byNumberFormat
. Instead, it causes a text such as "± 30 m" to be appended after the coordinates. -
accuracyThreshold
private transient double accuracyThresholdValue ofdesiredPrecisions
which causeaccuracyText
to be shown. For each dimension identified bygroundDimensions
, if the corresponding value indesiredPrecisions
is equal or smaller to this threshold, thenaccuracyText
will be appended after the formatted coordinates.- See Also:
-
groundDimensions
private transient long groundDimensionsThe dimensions on whichgroundPrecision
applies, specified as a bitmask. This bitmask is computed byapplyGroundPrecision(CoordinateReferenceSystem)
when first needed. The current heuristic rules are:- All axes having a
compass direction
if at least one of those axes uses an unit of measurement compatible with the unit ofgroundPrecision
(possibly after conversion between linear and angular units on a sphere). - Otherwise all axes using compatible units, regardless their direction and without conversion between linear and angular units.
- All axes having a
-
desiredPrecisions
private double[] desiredPrecisionsThe desired precisions for each coordinate, ornull
if unspecified. The unit of measurement is given byCoordinateSystemAxis.getUnit()
. The length of this array does not need to be equal to the number of dimensions; extraneous values are ignored and missing values are assumed equal to 0. A value of 0 means to use the default precision for that dimension.Note that this is the precision specified by the user, which may differ from the precision returned by
getPrecisions()
.- See Also:
-
isPrecisionApplied
private transient boolean isPrecisionAppliedWhether thisCoordinateFormat
instance has been configured for the precision and accuracy specified bygroundPrecision
,desiredPrecisions
andgroundAccuracy
. We use a field separated fromlastCRS
because precision and accuracy threshold need to be set only for formatting, not for parsing. -
isAccuracyVisible
private transient boolean isAccuracyVisibleWhether to append the accuracy after coordinate values. This flag istrue
ifaccuracyText
is non-null and one of the following conditions is true:desiredPrecisions
is null, in which case the accuracy is unconditionally shown.- At least one
desiredPrecisions
value is belowaccuracyThreshold
.
isPrecisionApplied
istrue
. -
defaultCRS
private org.opengis.referencing.crs.CoordinateReferenceSystem defaultCRSThe coordinate reference system to assume if no CRS is attached to the position to format. May benull
.- See Also:
-
lastCRS
private transient org.opengis.referencing.crs.CoordinateReferenceSystem lastCRSThe coordinate reference system of the lastDirectPosition
that we parsed or formatted. This is used for determining if we need to recompute all other transient fields in this class.- See Also:
-
LONGITUDE
private static final byte LONGITUDEConstants for thetypes
array.- See Also:
-
LATITUDE
private static final byte LATITUDEConstants for thetypes
array.- See Also:
-
ANGLE
private static final byte ANGLEConstants for thetypes
array.- See Also:
-
DATE
private static final byte DATEConstants for thetypes
array.- See Also:
-
TIME
private static final byte TIMEConstants for thetypes
array.- See Also:
-
INDEX
private static final byte INDEXConstants for thetypes
array.- See Also:
-
types
private transient byte[] typesThe type for each value in theformats
array, ornull
if not yet computed. Types are: 0=number, 1=longitude, 2=latitude, 3=other angle, 4=date, 5=elapsed time, 6=index.This array is created by
createFormats(CoordinateReferenceSystem)
, which is invoked before parsing or formatting in a different CRS than last operation, and stay unmodified after creation.- See Also:
-
formats
The formats to use for formatting each coordinate value, ornull
if not yet computed. The length of this array should be equal to the number of dimensions inlastCRS
. Values at different indices may reference the sameFormat
instance.- See Also:
-
units
private transient javax.measure.Unit<?>[] unitsThe units for each dimension to be formatted as a number with an unit of measurement. We do not storeUnit
instances for dimensions to be formatted as angles or dates because those quantities are formatted with specializedFormat
instances working in fixed units; no unit symbol should appear after dates or DD°MM′SS″ angles.We use this
units
array at parsing time for converting numbers from the units of measurement in the parsed text to units expected by thisCoordinateFormat
. Whether an element is non-null determines whether an unit symbol is allowed to appear in the text to parse for the corresponding dimension.All non-null elements in this array are
CoordinateSystemAxis.getUnit()
return values. This array is created bycreateFormats(CoordinateReferenceSystem)
, which is invoked before parsing or formatting in a different CRS than last operation, and stay unmodified after creation.- See Also:
-
toFormatUnit
private transient javax.measure.UnitConverter[] toFormatUnitConversions from arbitrary units to the unit used by formatter, ornull
if none. For example if coordinate at dimension i is formatted as an angle, thentoFormatUnit[i]
is the conversion from angular axis units to decimal degrees before those degrees are formatted as DD°MM′SS″ withAngleFormat
. Note that in this case,units[i] == null
for telling that no unit symbol should appear after the coordinate formatted in dimension i (because degree, minute and second symbols are handled byAngleFormat
instead).In addition to conversions required by formatters expecting values in fixed units of measurement,
toFormatUnit[i]
may also be non-null for some coordinates formatted as numbers if a different unit of measurement is desired. For example, the converter may be non-null if some coordinates in metres should be shown in kilometres. In those cases,units[i] != null
.This array is used in slightly different ways at parsing time and formatting time. At formatting time, coordinate values and unconditionally converted using all converters and the
units
array is ignored. At parsing time,toFormatUnit[i]
converters are used only in dimensions i where the parser requires a fixed unit which is implicit in the text (units[i] == null
). For other dimensions accepting various units (units[i] != null
), the converter to use is determined by the unit of measurement written in the text.This array is created by
createFormats(CoordinateReferenceSystem)
, which is invoked before parsing or formatting in a different CRS than last operation. It may be modified after creation as a result ofsetPrecisions(double...)
calls, for example for replacing a "m" unit by "km".- See Also:
-
unitSymbols
Units symbols to append after coordinate values for each dimension, including leading space. This is used only for coordinates to be formatted as ordinary numbers withNumberFormat
. This array is non-null only if at least one dimension needs to format its coordinates that way.Units symbols may be followed by axis direction symbols used for axes on the ground ("E", "N", "SW", etc.) so the complete symbol may be for example "km E". Those direction symbols are stored in a separated array; they are not part of elements of this
unitSymbols
array.This array is created by
createFormats(CoordinateReferenceSystem)
, which is invoked before parsing or formatting in a different CRS than last operation. It may be modified after creation as a result ofsetPrecisions(double...)
calls, for example for replacing a "m" unit by "km". -
unitSymbolsUnscaled
Same asunitSymbols
but without the changes applied bysetPrecisions(double...)
. This array is created bycreateFormats(CoordinateReferenceSystem)
, which is invoked before parsing or formatting in a different CRS than last operation, and stay unmodified after creation.- See Also:
-
directionSymbols
Directions symbols ("E", "N", "SW", etc.) to append after coordinate values for some dimensions, including leading space. This is used only for some coordinates formatted withNumberFormat
. This array is non-null only if at least one dimension needs to format its coordinates that way. The length of this array is twice the number of dimensions. The array contains this tuple:- Symbol of axis direction (at even indices)
- Symbol in the direction opposite to axis direction (at odd indices)
This array is created by
createFormats(CoordinateReferenceSystem)
, which is invoked before parsing or formatting in a different CRS than last operation, and stay unmodified after creation. -
accuracyText
Text to append to the coordinate values for giving an indication about accuracy, ornull
if none. Example: " ± 1 m" (note the leading space). This is determined by thegroundAccuracy
value. IfdesiredPrecisions
array is non-null, then accuracy is shown only if a precision is smaller. -
negate
private transient long negateFlags the coordinate values that need to be inverted before to be formatted. This is needed for example if the axis is oriented toward past instead of future, or toward west instead of east.- See Also:
-
epochs
private transient long[] epochsThe time epochs. Non-null only if the at least on coordinate is to be formatted as a date.This array is created by
createFormats(CoordinateReferenceSystem)
, which is invoked before parsing or formatting in a different CRS than last operation, and stay unmodified after creation. -
dummy
Dummy field position. -
buffer
Temporary buffer to use if thetoAppendTo
argument given toformat(DirectPosition, Appendable)
is not an instance ofStringBuffer
.
-
-
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
public org.opengis.referencing.crs.CoordinateReferenceSystem 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
public void setDefaultCRS(org.opengis.referencing.crs.CoordinateReferenceSystem crs) 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.
-
createFormats
private void createFormats(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Computes the values of transient fields from the given CRS. ThelastCRS
field is set to the given CRS for allowing callers to check if this method needs to be invoked again (this method does not check by itself). This method does not configure the formats for precisions specified bysetPrecisions(double...)
and related methods; that work is done byconfigure(CoordinateReferenceSystem)
at formatting time (it is not needed at parsing time).- Parameters:
crs
- the CRS for which to create theFormat
instances.- See Also:
-
symbol
Returns the symbol ("E", "N", "SW", etc.) for given axis direction. -
getFormatClone
Returns a clone of the format at the specified dimension. Format instances are cloned only when first needed. The clones are needed when we want to change the format pattern (number of fraction digits, etc.) for only one dimension, without impacting other dimensions that may use the same format. -
getDefaultFormat
The default format to use when no CRS or no axis information is available. The coordinate type could be anything (a date, an angle, …), but since we have no information we assume a number. This method is defined for making clearer when such fallback is used. -
setConverter
private void setConverter(int dimension, int i, javax.measure.UnitConverter c) Sets at the given index a conversion from CRS units to units used by this formatter.- Parameters:
dimension
- number of dimensions of the coordinate system.i
- index of the dimension for which to set the converter.c
- the converter to set at the given dimension.
-
scaleUnit
private <Q extends javax.measure.Quantity<Q>> void scaleUnit(int i, javax.measure.Unit<Q> unit) Replaces the "m" or "Pa" units of measurement in the given dimension by "km" or "kPa" or other units. This is invoked for modifying the format created bycreateFormats(CoordinateReferenceSystem)
according the value given tosetPrecisions(double...)
.Limitation
Current implementation assumes that there is only one scale factor allowed byCoordinateFormat
, which is 1000. If a future SIS version allows different scale factors, then we would need to make theif (toFormatUnit[i] == null)
check more accurate inapplyPrecision(int)
method.- Parameters:
i
- index of the dimension for which to change the unit.unit
- value ofunits[dimension]
.
-
negate
private void negate(int dimension) Remembers that coordinate values at the given dimension will need to have their sign reverted. -
isNegative
private boolean isNegative(int dimension) Returnstrue
if the value at the given dimension needs to have its sign reversed. -
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:
-
applyPrecision
private void applyPrecision(int dim) Sets the pattern of the format for the specified dimension according the desired precision. The format to configure isformats[dim]
and the pattern will be constructed from thedesiredPrecisions[dim]
value. Caller must ensure that the given dimension is valid for bothformats
anddesiredPrecisions
arrays. -
configure
private void configure(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Computes the values of transient fields from the given CRS and configure the format precisions. This method updates thelastCRS
andisPrecisionApplied
fields. This method does nothing if above-cited fields are already up to date.- Parameters:
crs
- the CRS for which to create and configure theFormat
instances.- See Also:
-
setGroundPrecision
public void setGroundPrecision(javax.measure.Quantity<?> precision) 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
public void setGroundAccuracy(javax.measure.Quantity<?> accuracy) 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:
-
applyGroundPrecision
private void applyGroundPrecision(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Configures the formats forgroundPrecision
value. Contrarily toapplyPrecision(int)
, this method modifies the default formats provided byCompoundFormat.getFormat(Class)
. They are the formats stored in thesharedFormats
array. Those formats are used as fallback when theformats
array does not provide more specific format.It is caller responsibility to ensure that
groundPrecision
is non-null before to invoke this method.- Parameters:
crs
- the target CRS in the conversion from ground units to CRS units.
-
applyGroundAccuracy
private void applyGroundAccuracy(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Updates theaccuracyThreshold
for the currentgroundAccuracy
value (which may be null) and the given coordinate reference system. -
updateAccuracyVisibility
private void updateAccuracyVisibility()Updates theisAccuracyVisible
flag according current values ofaccuracyText
,accuracyThreshold
anddesiredPrecisions
. -
getGroundAccuracy
public javax.measure.Quantity<?> 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<org.opengis.geometry.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<org.opengis.geometry.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
public void format(org.opengis.geometry.DirectPosition position, Appendable toAppendTo) throws IOException 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<org.opengis.geometry.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
public org.opengis.geometry.DirectPosition parse(CharSequence text, ParsePosition pos) throws ParseException 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<org.opengis.geometry.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.
-
unexpectedException
Invoked when an expected error occurred but continuation is still possible.- Parameters:
method
- the public method to report as the source of the log record.error
- the error that occurred.
-
clone
Returns a clone of this format.- Overrides:
clone
in classCompoundFormat<org.opengis.geometry.DirectPosition>
- Returns:
- a clone of this format.
-
readObject
Invoked on deserialization for restoring some transient fields.- Parameters:
in
- the input stream from which to deserialize a coordinate format- Throws:
IOException
- if an I/O error occurred while reading or if the stream contains invalid data.ClassNotFoundException
- if the class serialized on the stream is not on the classpath.
-