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 NumberFormatfollowed 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:
Defined in the sis-referencing module
- 
Nested Class SummaryNested classes/interfaces inherited from class FormatFormat.Field
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs 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 SummaryModifier and TypeMethodDescriptionbooleanapplyPattern(Class<?> valueType, String pattern) Sets the pattern for number, angle or date fields.clone()Returns a clone of this format.protected FormatcreateFormat(Class<?> valueType) Creates a new format to use for parsing and formatting values of the given type.format(DirectPosition position) Formats the given coordinate.voidformat(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, ornullif 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 thisFormatinstance.parse(CharSequence text, ParsePosition pos) Parses a coordinate from the given character sequence.voidSets the coordinate reference system to use if no CRS is explicitly associated to a givenDirectPosition.voidsetGroundAccuracy(Quantity<?> accuracy) Specifies an uncertainty to append as "± accuracy" after the coordinate values.voidsetGroundPrecision(Quantity<?> precision) Adjusts the number of fraction digits to show in coordinates for achieving the given precision.voidsetPrecisions(double... precisions) Sets the desired precisions at which to format coordinate values in each dimension.voidsetSeparator(String separator) Sets the separator between each coordinate.Methods inherited from class CompoundFormatformat, getFormat, getLocale, getLocale, getTimeZone, parseObject, parseObjectMethods inherited from class Formatformat, formatToCharacterIterator
- 
Constructor Details- 
CoordinateFormatpublic CoordinateFormat()Constructs a new coordinate format with default locale and timezone.
- 
CoordinateFormatConstructs a new coordinate format for the specified locale and timezone.- Parameters:
- locale- the locale for the new- Format, or- nullfor- Locale.ROOT.
- timezone- the timezone, or- nullfor UTC.
 
 
- 
- 
Method Details- 
getSeparatorReturns the separator between each coordinate (number, angle or date). The default value is a single space.- Returns:
- the current coordinate separator.
 
- 
setSeparatorSets the separator between each coordinate. The default value is a single space.- Parameters:
- separator- the new coordinate separator.
 
- 
getDefaultCRSReturns 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 nullif none.
 
- 
setDefaultCRSSets 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, or- nullif none.
 
- 
getPrecisionspublic 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:
 
- 
setPrecisionspublic 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 or- Double.NaNvalues for unspecified precisions in some of those dimensions), or- nullfor restoring the default values.
- Since:
- 1.1
- See Also:
 
- 
setGroundPrecisionAdjusts the number of fraction digits to show in coordinates for achieving the given precision. TheNumberFormatandAngleFormatare 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:
 
- 
setGroundAccuracySpecifies 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, or- nullif none.
- Since:
- 1.1
- See Also:
 
- 
getGroundAccuracyReturns the current ground accuracy value, ornullif none. This is the value given to the last call tosetGroundAccuracy(Quantity).- Returns:
- the current ground accuracy value, or nullif none.
- See Also:
 
- 
getGroundAccuracyTextReturns the textual representation of the current ground accuracy. Example: " ± 3 m" (note the leading space).- Returns:
- textual representation of current ground accuracy.
- See Also:
 
- 
getPatternReturns the pattern for number, angle or date fields. The givenvalueTypeshould beNumber.class,Angle.class,Date.classor a sub-type of the above. This method may returnnullif the underlying format cannot provide a pattern.Pattern availability for type of value Value type Base format class Format with pattern NumberNumberFormatDecimalFormatAngleAngleFormatAngleFormatDateDateFormatSimpleDateFormat- Parameters:
- valueType- the base type of coordinate values to parse and format:- Number.class,- Angle.classor- Date.class.
- Returns:
- the pattern for fields of the given type, or nullif not applicable.
- See Also:
 
- 
applyPatternSets the pattern for number, angle or date fields. The pattern syntax depends on thevalueTypeargument:- If valueTypeisNumber.class, then the pattern syntax shall be as described in theDecimalFormatclass. This pattern may be used for any coordinate to be formatted as plain number, for example in Cartesian coordinate system.
- If valueTypeisAngle.class, then the pattern syntax shall be as described in theAngleFormatclass. This pattern may be used for any coordinate to be formatted as latitude or longitude, for example in ellipsoidal coordinate system.
- If valueTypeisDate.class, then the pattern syntax shall be as described in theSimpleDateFormatclass. 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.classor- Date.class.
- pattern- the pattern as specified in- DecimalFormat,- AngleFormator- SimpleDateFormatjavadoc.
- Returns:
- trueif the pattern has been applied, or- falseif- valueTypedoes 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 
- 
getValueTypeReturns the base type of values parsed and formatted by thisFormatinstance.- Specified by:
- getValueTypein class- CompoundFormat<DirectPosition>
- Returns:
- DirectPosition.class.
 
- 
createFormatCreates 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:
- createFormatin class- CompoundFormat<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 nullif none.
 
- 
formatFormats 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.
 
- 
formatFormats 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:
- formatin class- CompoundFormat<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 of- longtype.
 
- 
parseParses 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 theposargument. If parsing succeeds, then theposindex is updated to the index after the last coordinate value and the parsed coordinate is returned. Otherwise (if parsing fails), theposindex is left unchanged, theposerror index is set to the index of the first unparsable character and an exception is thrown with a similar error index.- Specified by:
- parsein class- CompoundFormat<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.
 
- 
cloneReturns a clone of this format.- Overrides:
- clonein class- CompoundFormat<DirectPosition>
- Returns:
- a clone of this format.
 
 
-