Class LocationFormat

All Implemented Interfaces:
Serializable, Cloneable, Localized

public class LocationFormat extends TabularFormat<AbstractLocation>
Formats Location instances in a tabular format. This format assumes a monospaced font and an encoding supporting drawing box characters (e.g. UTF-8).
Example: the location identified by "32TNL83" in the military grid reference system can be represented by the following string formatted using Locale.ENGLISH:

Limitations

  • The current implementation can only format features — parsing is not yet implemented.
  • LocationFormat, like most java.text.Format subclasses, is not thread-safe.
Since:
0.8
Version:
0.8
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • INSTANCE

      static final LocationFormat INSTANCE
      Default instance for AbstractLocation.toString(). Use of this instance must be synchronized on INSTANCE.
    • BOUND_KEY

      private static final short[] BOUND_KEY
      Vocabulary.Keys constants for the east, west, south and north bounds, in that order.
  • Constructor Details

    • LocationFormat

      public LocationFormat(Locale locale, TimeZone timezone)
      Creates a new format for the given locale. The given locale can be null or Locale.ROOT if this format shall format "unlocalized" strings.
      Parameters:
      locale - the locale for the new Format, or null for Locale.ROOT.
      timezone - the timezone, or null for UTC.
  • Method Details

    • getValueType

      public Class<AbstractLocation> getValueType()
      Returns the type of values formatted by this Format instance.
      Specified by:
      getValueType in class CompoundFormat<AbstractLocation>
      Returns:
      the type of values formatted by this Format instance.
    • normalize

      private static org.opengis.referencing.crs.CoordinateReferenceSystem normalize(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
      Returns a CRS equivalent to the given one but with (longitude, latitude) or (easting, northing) axis order. This method does not change the units of measurement. If the given CRS is already normalized, then it is returned unchanged.
    • transform

      private static org.opengis.geometry.DirectPosition transform(org.opengis.geometry.DirectPosition position, org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException
      Transforms the given position from the given source to the given target CRS. If the source and target CRS are the same, then this method returns the position unchanged.
      Throws:
      org.opengis.util.FactoryException
      org.opengis.referencing.operation.TransformException
    • position

      private static org.opengis.geometry.DirectPosition position(org.opengis.geometry.coordinate.Position p)
      Returns the direct position for the given position, or null if none.
    • toString

      private static String toString(org.opengis.util.InternationalString i18n, Locale locale)
      Returns a localized version of the given international string, or null if none.
    • toString

      private String toString(Date date)
      Returns a localized version of the given date, or null if none.
    • format

      public void format(AbstractLocation location, Appendable toAppendTo) throws IOException
      Writes a textual representation of the given location in the given stream or buffer.
      Upcoming API change — generalization
      in a future SIS version, the type of location parameter may be generalized to the org.opengis.referencing.gazetteer.Location interface. This change is pending GeoAPI revision.
      Specified by:
      format in class CompoundFormat<AbstractLocation>
      Parameters:
      location - the location to format.
      toAppendTo - where to format the location.
      Throws:
      IOException - if an error occurred while writing to the given appendable.
    • createFormat

      protected Format createFormat(Class<?> valueType)
      Creates the format to use for formatting a latitude, longitude or projected coordinate. This method is invoked by format(Location, Appendable) when first needed.
      Overrides:
      createFormat in class CompoundFormat<AbstractLocation>
      Parameters:
      valueType - Angle.class. Number.class or Unit.class.
      Returns:
      a new AngleFormat, NumberFormat or UnitFormat instance depending on the argument value.
    • append

      private void append(TableAppender table, Vocabulary vocabulary, short key, String value) throws IOException
      Appends the given value in the given table if it is not null.
      Parameters:
      table - the table where to append the value.
      vocabulary - localized resources for the labels.
      key - key of the label to append.
      value - value to append, or null if none.
      Throws:
      IOException
    • nextColumn

      private void nextColumn(TableAppender table)
      Moves to the next column.
    • parse

      public AbstractLocation parse(CharSequence text, ParsePosition pos) throws ParseException
      Unsupported operation.
      Specified by:
      parse in class CompoundFormat<AbstractLocation>
      Parameters:
      text - the character sequence for the location to parse.
      pos - the position where to start the parsing.
      Returns:
      the parsed location, or null if the text is not recognized.
      Throws:
      ParseException - if an error occurred while parsing the location.
    • clone

      public LocationFormat clone()
      Returns a clone of this format.
      Overrides:
      clone in class TabularFormat<AbstractLocation>
      Returns:
      a clone of this format.