Class MilitaryGridReferenceSystem.Decoder

All Implemented Interfaces:
org.opengis.geometry.coordinate.Position, org.opengis.geometry.DirectPosition, org.opengis.geometry.Envelope, org.opengis.metadata.extent.GeographicBoundingBox, org.opengis.metadata.extent.GeographicExtent
Enclosing class:
MilitaryGridReferenceSystem

static final class MilitaryGridReferenceSystem.Decoder extends SimpleLocation.Projected
The result of decoding a MGRS reference. The position represents the centroid of the decoded MGRS reference.
Since:
0.8
Version:
0.8
  • Field Details

    • NORTHING_BITS_COUNT

      static final int NORTHING_BITS_COUNT
      Number of bits reserved for storing the minimal northing value of latitude bands in the ROW_RESOLVER table.
      See Also:
    • NORTHING_BITS_MASK

      static final int NORTHING_BITS_MASK
      Mask over the 4 lowest bits.
      See Also:
    • ROW_RESOLVER

      private static final int[] ROW_RESOLVER
      Mapping from latitude bands to the minimal northing values, together with the set of valid rows. There is 20 latitude bands identified by letters C to X inclusively, with letters I and O skipped. First, the band letter must be converted to an index i in the [0 … 19] range. Then, the ROW_RESOLVER[i] integer values provides the following information:
      • The lowest 4 bits gives the minimal northing value of all valid coordinates in the latitude band, as a multiple of the number of metres in a full cycle of 20 rows. That northing value can be computed in metre as below:
      • Given a row number row in the [0 … 19] range, the following expression tells if that row can be inside the latitude band: Note that the same row may be valid in two consecutive latitude bands. The trailing _0000 parts make room for 4 bits.
      The content of this table is verified by MilitaryGridReferenceSystemTest.verifyDecoderTables(). The same method with minor edition can be used for generating this table.
    • crs

      private final org.opengis.referencing.crs.ProjectedCRS crs
      The Coordinate Reference System of the decoded MGRS reference. This is an Universal Transverse Mercator (UTM) or Universal Polar Stereographic (UPS) projection.
      See Also:
  • Constructor Details

    • Decoder

      Decoder(MilitaryGridReferenceSystem.Coder owner, CharSequence reference) throws org.opengis.referencing.operation.TransformException
      Decodes the given MGRS reference.
      Parameters:
      owner - the Coder which is creating this Decoder.
      Throws:
      org.opengis.referencing.operation.TransformException
  • Method Details

    • nextComponent

      private static int nextComponent(MilitaryGridReferenceSystem.Coder owner, CharSequence reference, int base, int start, int end) throws GazetteerException
      Skips spaces, then the separator if present (optional).
      Parameters:
      reference - the reference to parse.
      base - index where the parsing began. Used for formatting error message only.
      start - current parsing position.
      end - where the parsing is expected to end.
      Returns:
      position where to continue parsing (with spaces skipped).
      Throws:
      GazetteerException - if this method unexpectedly reached the end of string.
    • isLetter

      private static boolean isLetter(int c)
      Returns true if the given character is a valid upper case ASCII letter, excluding I and O.
    • endOfDigits

      private static int endOfDigits(CharSequence reference, int i, int end)
      Returns the index after the last digit in a sequence of ASCII characters. Leading whitespaces must have been skipped before to invoke this method.
    • parseInt

      private static int parseInt(CharSequence reference, int start, int end, short errorKey) throws GazetteerException
      Parses part of the given character sequence as an integer.
      Parameters:
      reference - the MGRS reference to parse.
      start - index of the first character to parse as an integer.
      end - index after the last character to parse as an integer.
      errorKey - Resources.Keys value to use in case of error. The error message string shall accept exactly one argument.
      Returns:
      the parsed integer.
      Throws:
      GazetteerException - if the string cannot be parsed as an integer.
    • parseCoordinate

      private static double parseCoordinate(CharSequence reference, int start, int end, double scale) throws GazetteerException
      Parses part of the given character sequence as a grid coordinate. The resolution is determined by the amount of digits.
      Parameters:
      reference - the MGRS reference to parse.
      start - index of the first character to parse as a grid coordinate.
      end - index after the last character to parse as a grid coordinate.
      scale - value of MathFunctions.pow10(METRE_PRECISION_DIGITS - (end - start)).
      Returns:
      the parsed grid coordinate (also referred to as rectangular coordinates).
      Throws:
      GazetteerException - if the string cannot be parsed as a grid coordinate.
    • upperBound

      static double upperBound(double φ)
      Returns the upper bound of the latitude band specified by the given lower bound.
    • getCoordinateReferenceSystem

      public org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()
      Returns the Coordinate Reference System of the decoded MGRS reference. This is an Universal Transverse Mercator (UTM) or Universal Polar Stereographic (UPS) projection.
      Specified by:
      getCoordinateReferenceSystem in interface org.opengis.geometry.DirectPosition
      Specified by:
      getCoordinateReferenceSystem in interface org.opengis.geometry.Envelope
      Overrides:
      getCoordinateReferenceSystem in class SimpleLocation