Class TLcdCGRSFormat

java.lang.Object
java.text.Format
com.luciad.text.cgrs.TLcdCGRSFormat
All Implemented Interfaces:
ILcdFormatter, ILcdParser, Serializable, Cloneable

public class TLcdCGRSFormat extends Format implements ILcdFormatter, ILcdParser
This class offers methods to format coordinates into the Common Grid Reference System (CGRS) notation. This class also offers methods to parse a CGRS coordinate string into a point object.

The formatting and parsing of CGRS coordinate strings can be customized using a CGRS format String. An example of a CGRS coordinate string is 25AC5NE. This string consists of

  • 25: A number identifying the northing component of a 30 minutes square.
  • AC: Letters identifying the easting component of a 30 minutes square.
  • 5: One cipher identifying a 10 minute square within this 30 minutes square.
  • NE: Two letters identifying a 5 minute square within this 10 minutes square.

Since:
2021.1
See Also:
  • Field Details

    • DEFAULT_CGRS_FORMAT_CELL

      public static final String DEFAULT_CGRS_FORMAT_CELL
      A default CGRS format which describes a cell
      See Also:
    • DEFAULT_CGRS_FORMAT_KEYPAD

      public static final String DEFAULT_CGRS_FORMAT_KEYPAD
      A default CGRS format which describes a cell and keypad
      See Also:
    • DEFAULT_CGRS_FORMAT_QUADRANT

      public static final String DEFAULT_CGRS_FORMAT_QUADRANT
      A default CGRS format which describes a cell, keypad and quadrant
      See Also:
  • Constructor Details

    • TLcdCGRSFormat

      public TLcdCGRSFormat(ILcdBounds aGridBounds, String aCGRSFormat)
      Creates a new TLcdCGRSFormat that uses the given grid bounds for its calculations and that uses the given CGRS format to format or parse an ILcdPoint.

      The format should be expressed in EBNF notation (expressions enclosed in [] brackets are optional, expressions enclosed in {} brackets may be omitted or repeated):

       <pattern>                       ::= <cellY> {<separator>} <cellX> [{<separator>} <keypad>] [{<separator>} <quadrant>]
       <cellY>                         ::= "Y" | "Y", <cellMinimumCharacterLength>
       <cellX>                         ::= "X" | "X", <cellMinimumCharacterLength>
       <keypad>                        ::= "K"
       <quadrant>                      ::= "Q"
       <cellMinimumCharacterLength>    ::= "1" | "2" | "3"
       <separator>                     ::= { ? any character ? }
       
      When the minimum character length is higher than the amount of actual characters, it will be padded with default characters. For X it will be padded with " " (space), for Y it will be padded with "0" (zero). When the minimum character length is lower than or equal to the amount of characters, the minimum character length has no effect. For example:
      • "340X5NW" has format "YXKQ"
      • "182_ QW_NE_3" has format "Y3_X3_Q_K"

      Parameters:
      aGridBounds - given bounds expressed in the WGS84 reference. The values are rounded to the nearest multiple of 30 minutes. This parameter should never be null.
      aCGRSFormat - given CGRS format, never null
      Throws:
      NullPointerException - if aGridBounds or aCGRSFormat is null.
  • Method Details

    • format

      public StringBuffer format(Object aObject, StringBuffer aToAppendTo, FieldPosition aPosition)
      Specified by:
      format in class Format
    • parseObject

      public Optional<ILcdPoint> parseObject(String aString, ParsePosition aPosition)
      Parses text from a CGRS coordinate string to produce an ILcdPoint with longitude latitude coordinates in the same geodetic reference as the grid bounds that were used to construct this TLcdCGRSFormat.

      The method attempts to parse a string representing a CGRS coordinate, starting at the index given by aPosition. Parsing does not necessarily use all characters up to the end of the string. If parsing succeeds, the index of aPosition is updated to the index after the last character used, and the parsed object is returned. The updated aPosition can be used to indicate the starting point for the next call to this method. If an error occurs, the index of aPosition is not changed. The error index of aPosition is set to the index of the character where the error occurred, and Optional.empty() is returned.

      Specified by:
      parseObject in class Format
      Parameters:
      aString - A String representing a CGRS coordinate, part of which should be parsed, never null.
      aPosition - A ParsePosition object with index and error index information as described above, never null.
      Returns:
      An Optional containing an ILcdPoint parsed from the string. In case of error, returns Optional.empty().
      Throws:
      NullPointerException - if aSource or aPosition is null.
      See Also:
    • parse

      public ILcdPoint parse(String aString) throws IllegalArgumentException
      Parses a given String and creates a new ILcdPoint with longitude latitude coordinates in the same geodetic reference as the grid bounds that were used to construct this TLcdCGRSFormat.
      Specified by:
      parse in interface ILcdParser
      Parameters:
      aString - the String representing a CGRS coordinate to be parsed, never null.
      Returns:
      an ILcdPoint
      Throws:
      NullPointerException - if aString is null.
      IllegalArgumentException - if the String can't be parsed.