Class MGRSCoord


  • public class MGRSCoord
    extends java.lang.Object
    This class holds an immutable MGRS coordinate string along with the corresponding latitude and longitude.
    • Constructor Summary

      Constructors 
      Constructor Description
      MGRSCoord​(double latitude, double longitude, java.lang.String MGRSString)
      Create an arbitrary MGRS coordinate from a pair of latitude-longitude double and the corresponding MGRS coordinate string.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static MGRSCoord fromLatLon​(double latitude, double longitude)
      Create a WGS84 MGRS coordinate from a pair of latitude and longitude double with the maximum precision of five digits (one meter).
      static MGRSCoord fromLatLon​(double latitude, double longitude, int precision)
      Create a MGRS coordinate from a pair of latitude and longitude double with the given precision or number of digits (1 to 5).
      static MGRSCoord fromString​(java.lang.String MGRSString)
      Create a MGRS coordinate from a standard MGRS coordinate text string.
      double getLatitude()  
      double getLongitude()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • MGRSCoord

        public MGRSCoord​(double latitude,
                         double longitude,
                         java.lang.String MGRSString)
        Create an arbitrary MGRS coordinate from a pair of latitude-longitude double and the corresponding MGRS coordinate string.
        Parameters:
        latitude - the latitude double.
        longitude - the longitude double.
        MGRSString - the corresponding MGRS coordinate string.
        Throws:
        java.lang.IllegalArgumentException - if latitude or longitude is null, or the MGRSString is null or empty.
    • Method Detail

      • fromLatLon

        public static MGRSCoord fromLatLon​(double latitude,
                                           double longitude)
        Create a WGS84 MGRS coordinate from a pair of latitude and longitude double with the maximum precision of five digits (one meter).
        Parameters:
        latitude - the latitude double.
        longitude - the longitude double.
        Returns:
        the corresponding MGRSCoord.
        Throws:
        java.lang.IllegalArgumentException - if latitude or longitude is null, or the conversion to MGRS coordinates fails.
      • fromLatLon

        public static MGRSCoord fromLatLon​(double latitude,
                                           double longitude,
                                           int precision)
        Create a MGRS coordinate from a pair of latitude and longitude double with the given precision or number of digits (1 to 5).
        Parameters:
        latitude - the latitude double.
        longitude - the longitude double.
        precision - the number of digits used for easting and northing (1 to 5).
        Returns:
        the corresponding MGRSCoord.
        Throws:
        java.lang.IllegalArgumentException - if latitude or longitude is null, or the conversion to MGRS coordinates fails.
      • fromString

        public static MGRSCoord fromString​(java.lang.String MGRSString)
        Create a MGRS coordinate from a standard MGRS coordinate text string.

        The string will be converted to uppercase and stripped of all spaces before being evaluated.

        Valid examples:
        32TLP5626635418
        32 T LP 56266 35418
        11S KU 528 111

        Parameters:
        MGRSString - the MGRS coordinate text string.
        Returns:
        the corresponding MGRSCoord.
        Throws:
        java.lang.IllegalArgumentException - if the MGRSString is null or empty, the globe is null, or the conversion to geodetic coordinates fails (invalid coordinate string).
      • getLatitude

        public double getLatitude()
      • getLongitude

        public double getLongitude()
      • toString

        @NonNull
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object