Class MilitaryGridReferenceSystem.Encoder

java.lang.Object
org.apache.sis.referencing.gazetteer.MilitaryGridReferenceSystem.Encoder
Enclosing class:
MilitaryGridReferenceSystem

static final class MilitaryGridReferenceSystem.Encoder extends Object
Conversions from direct positions to Military Grid Reference System (MGRS) references. Each Encoder instance is configured for one DirectPosition CRS. If a position is given in another CRS, another Encoder instance must be created.

Immutability and thread safety

This class is not thread-safe. A new instance must be created for each thread, or synchronization must be applied by the caller.
Since:
0.8
Version:
1.3
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    The actual zone where the position to encode is located.
    (package private) final int
    UTM zone of position CRS (negative for South hemisphere), or 100 (negative of positive) if the CRS is a Universal Polar Stereographic projection, or 0 if the CRS is not a recognized projection.
    private final CommonCRS
    The datum to which to transform the coordinates before formatting the MGRS reference.
    (package private) char
    The latitude band of the last encoded reference.
    private static final int
    Special crsZone value for the UPS (Universal Polar Stereographic) projection.
    private org.opengis.referencing.operation.MathTransform
    A transform from a position in the CRS given at construction time to a position in the CRS identified by actualZone.
    private final org.opengis.referencing.operation.MathTransform
    Coordinate conversion or transformation from the normalized CRS to geographic CRS.
    private final org.opengis.referencing.operation.MathTransform
    Coordinate conversion from the position CRS to a CRS of the same type but with normalized axes, or null if not needed.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Encoder(CommonCRS datum, org.opengis.referencing.crs.CoordinateReferenceSystem crs)
    Creates a new converter from direct positions to MGRS references.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    append(StringBuilder buffer, int value, int digits)
    Appends the given value in the given buffer, padding with zero digits in order to get the specified total amount of digits.
    (package private) String
    encode(MilitaryGridReferenceSystem.Coder owner, org.opengis.geometry.DirectPosition position, boolean reproject, String separator, int digits, double precision)
    Encodes the given position into a MGRS reference.
    (package private) final double
    getLatitude(MilitaryGridReferenceSystem.Coder owner, org.opengis.geometry.DirectPosition position)
    Returns the latitude in degrees of given position.
    (package private) static char
    latitudeBand(double φ)
    Returns the band letter for the given latitude.
    private static char
    letter(int c)
    Returns the given character as a char if it is a letter, or throws an exception otherwise.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • POLE

      private static final int POLE
      Special crsZone value for the UPS (Universal Polar Stereographic) projection. Positive value is used for North pole and negative value for South pole.
      See Also:
    • datum

      private final CommonCRS datum
      The datum to which to transform the coordinates before formatting the MGRS reference. Only the datums enumerated in CommonCRS are currently supported.
    • crsZone

      final int crsZone
      UTM zone of position CRS (negative for South hemisphere), or 100 (negative of positive) if the CRS is a Universal Polar Stereographic projection, or 0 if the CRS is not a recognized projection. Note that this is not necessarily the same zone than the one to use for formatting any given coordinate in that projected CRS, since the TransverseMercator.Zoner.zone(double, double) method has special rules for some latitudes.
    • toNormalized

      private final org.opengis.referencing.operation.MathTransform toNormalized
      Coordinate conversion from the position CRS to a CRS of the same type but with normalized axes, or null if not needed. After conversion, axis directions will be (East, North) and axis units will be metres.

      This transform should perform only simple operations like swapping axis order and unit conversions. It should not perform more complex operations that would require to go back to geographic coordinates.

    • toGeographic

      private final org.opengis.referencing.operation.MathTransform toGeographic
      Coordinate conversion or transformation from the normalized CRS to geographic CRS. Axis directions are (North, East) as in EPSG geodetic dataset and axis units are degrees. This transform is never null.

      This transform may contain datum change from the position datum to the target datum.

    • toActualZone

      private org.opengis.referencing.operation.MathTransform toActualZone
      A transform from a position in the CRS given at construction time to a position in the CRS identified by actualZone. This field is updated only when a given position is not located in the zone of the CRS given at construction time.
    • actualZone

      private int actualZone
      The actual zone where the position to encode is located. Legal values are the same than crsZone. If non-zero, then this is the zone of the toActualZone transform. This field is updated only when a given position is not located in the zone of the CRS given at construction time.
    • latitudeBand

      char latitudeBand
      The latitude band of the last encoded reference. This information is provided for MilitaryGridReferenceSystem.IteratorOneZone purpose.
  • Constructor Details

    • Encoder

      Encoder(CommonCRS datum, org.opengis.referencing.crs.CoordinateReferenceSystem crs) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException
      Creates a new converter from direct positions to MGRS references.
      Parameters:
      datum - the datum to which to transform the coordinate before formatting the MGRS reference, or null for inferring the datum from the given crs.
      crs - the coordinate reference system of the coordinates for which to create MGRS references.
      Throws:
      IllegalArgumentException - if the given CRS do not use one of the supported datums.
      org.opengis.util.FactoryException - if the creation of a coordinate operation failed.
      org.opengis.referencing.operation.TransformException - if the creation of an inverse operation failed.
  • Method Details

    • latitudeBand

      static char latitudeBand(double φ)
      Returns the band letter for the given latitude. It is caller responsibility to ensure that the given latitude is between -80.0 and 84.0 inclusive. The returned letter will be one of "CDEFGHJKLMNPQRSTUVWX" (note that I and O letters are excluded). All bands are 8° height except the X band which is 12° height.
      Parameters:
      φ - the latitude in degrees for which to get the band letter.
      Returns:
      the band letter for the given latitude.
    • getLatitude

      final double getLatitude(MilitaryGridReferenceSystem.Coder owner, org.opengis.geometry.DirectPosition position) throws org.opengis.referencing.operation.TransformException
      Returns the latitude in degrees of given position. This is used only for estimating the precision.
      Throws:
      org.opengis.referencing.operation.TransformException
    • encode

      String encode(MilitaryGridReferenceSystem.Coder owner, org.opengis.geometry.DirectPosition position, boolean reproject, String separator, int digits, double precision) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException
      Encodes the given position into a MGRS reference. It is caller responsibility to ensure that the position CRS is the same than the CRS specified at this Encoder creation time.
      Parameters:
      owner - the Coder which own this Encoder.
      position - the direct position to format as a MGRS reference.
      reproject - whether this method is allowed to reproject position when needed.
      separator - the separator to insert between each component of the MGRS identifier.
      digits - number of digits to use for formatting the numerical part of a MGRS reference.
      precision - angular precision in radians, or 0. If non-zero, it will override digits.
      Returns:
      the value of buffer.toString(), or null if a reprojection was necessary but reproject is false.
      Throws:
      org.opengis.util.FactoryException
      org.opengis.referencing.operation.TransformException
    • letter

      private static char letter(int c) throws GazetteerException
      Returns the given character as a char if it is a letter, or throws an exception otherwise. The exception should never happen, unless the the encoder is used for a planet larger than Earth for which we do not have enough letters.
      Throws:
      GazetteerException
    • append

      private static void append(StringBuilder buffer, int value, int digits) throws GazetteerException
      Appends the given value in the given buffer, padding with zero digits in order to get the specified total amount of digits.
      Throws:
      GazetteerException