Class CoordinateFormat

    • Constructor Detail

      • CoordinateFormat

        public CoordinateFormat()
        Constructs a new coordinate format with default locale and timezone.
      • CoordinateFormat

        public CoordinateFormat​(Locale locale,
                                TimeZone timezone)
        Constructs a new coordinate format for the specified locale and timezone.
        Parameters:
        locale - the locale for the new Format, or null for Locale​.ROOT.
        timezone - the timezone, or null for UTC.
    • Method Detail

      • getSeparator

        public String getSeparator()
        Returns the separator between each coordinate (number, angle or date). The default value is a single space.
        Returns:
        the current coordinate separator.
      • setSeparator

        public void setSeparator​(String separator)
        Sets the separator between each coordinate. The default value is a single space.
        Parameters:
        separator - the new coordinate separator.
      • getDefaultCRS

        public CoordinateReferenceSystem getDefaultCRS()
        Returns the coordinate reference system to use if no CRS is explicitly associated to a given Direct­Position.
        Returns:
        the default coordinate reference system, or null if none.
      • setDefaultCRS

        public void setDefaultCRS​(CoordinateReferenceSystem crs)
        Sets the coordinate reference system to use if no CRS is explicitly associated to a given Direct­Position. 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 null if none.
      • setPrecision

        public void setPrecision​(double resolution,
                                 Unit<?> unit)
        Adjusts the number of fraction digits to show in coordinates for achieving the given precision. The Number­Format and Angle­Format are configured for coordinates expressed in the default coordinate reference system defined at the moment this method is invoked. The number of fraction digits is not updated if a different CRS is specified after this method call or if the coordinates to format are associated to a different CRS.

        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.

        Parameters:
        resolution - the desired resolution.
        unit - unit of the desired resolution.
        Since:
        1.0
        See Also:
        Number­Format​.set­Maximum­Fraction­Digits(int), Angle­Format​.set­Precision(double, boolean)
      • getPattern

        public String getPattern​(Class<?> valueType)
        Returns the pattern for number, angle or date fields. The given value­Type 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.
        Pattern availability for type of value
        Value type Base format class Format with pattern
        Number NumberFormat DecimalFormat
        Angle AngleFormat AngleFormat
        Date DateFormat SimpleDateFormat
        Parameters:
        value­Type - the base type of coordinate values to parse and format: Number​.class, Angle​.class or Date​.class.
        Returns:
        the pattern for fields of the given type, or null if not applicable.
        See Also:
        Compound­Format​.get­Format(Class)
      • applyPattern

        public boolean applyPattern​(Class<?> valueType,
                                    String pattern)
        Sets the pattern for number, angle or date fields. The pattern syntax depends on the value­Type argument:
        • If value­Type is Number​.class, then the pattern syntax shall be as described in the Decimal­Format class. This pattern may be used for any coordinate to be formatted as plain number, for example in Cartesian coordinate system.
        • If value­Type is Angle​.class, then the pattern syntax shall be as described in the Angle­Format class. This pattern may be used for any coordinate to be formatted as latitude or longitude, for example in ellipsoidal coordinate system.
        • If value­Type is Date​.class, then the pattern syntax shall be as described in the Simple­Date­Format class. This pattern may be used for any coordinate to be formatted as date and time, for example in time coordinate system.
        Parameters:
        value­Type - the base type of coordinate values to parse and format: Number​.class, Angle​.class or Date​.class.
        pattern - the pattern as specified in Decimal­Format, Angle­Format or Simple­Date­Format javadoc.
        Returns:
        true if the pattern has been applied, or false if value­Type does not specify a known type or if the format associated to that type does not support patterns.
        Throws:
        Illegal­Argument­Exception - if the given pattern is invalid.
      • format

        public String format​(DirectPosition position)
        Formats the given coordinate.
        Parameters:
        position - the coordinate to format.
        Returns:
        the formatted position.
      • format

        public void format​(DirectPosition position,
                           Appendable toAppendTo)
                    throws IOException
        Formats the given coordinate and appends the resulting text to the given stream or buffer.
        Specified by:
        format in class Compound­Format<Direct­Position>
        Parameters:
        position - the coordinate to format.
        to­Append­To - where the text is to be appended.
        Throws:
        IOException - if an error occurred while writing to the given appendable.
      • parse

        public 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 the pos argument. If parsing succeeds, then the pos index is updated to the index after the last coordinate 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.
        Specified by:
        parse in class Compound­Format<Direct­Position>
        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:
        Parse­Exception - if an error occurred while parsing the coordinate.