uk.me.jstott.jcoord
Class MGRSRef

java.lang.Object
  extended by uk.me.jstott.jcoord.CoordinateSystem
      extended by uk.me.jstott.jcoord.MGRSRef

public class MGRSRef
extends CoordinateSystem

This class is part of the Jcoord package. Visit the Jcoord website for more information.

Class to represent a Military Grid Reference System (MGRS) reference.

Military Grid Reference System (MGRS)

The Military Grid Reference System (MGRS) is an extension of the Universal Transverse Mercator (UTM) reference system. An MGRS reference is made from 5 parts:

UTM Longitude Zone

This is a number indicating which UTM longitude zone the reference falls into. Zones are numbered from 1 (starting at 180°W) through 60. Each zone is 6° wide.

UTM Latitude Zone

Latitude is split into regions that are 8° high, starting at 80°S. Latitude zones are lettered using C through X, but omitting I and O as they can easily be confused with the numbers 1 and 0.

100,000m Square identification

Each UTM zone is treated as a square 100,000m to a side. The 50,000m easting is centred on the centre-point of the UTM zone. 100,000m squares are identified using two characters - one to identify the row and one to identify the column.

Row identifiers use the characters A through V (omitting I and O again). The sequence is repeated every 2,000,000m from the equator. If the UTM longitude zone is odd, then the lettering is advanced by five characters to start at F.

Column identifiers use the characters A through Z (again omitting I and O).

Easting and northing

Each 100,000m grid square is further divided into smaller squares representing 1m, 10m, 100m, 1,000m and 10,000m precision. The easting and northing are given using the numeric row and column reference of the square, starting at the bottom-left corner of the square.

MGRS Reference Example

18SUU8362601432 is an example of an MGRS reference. '18' is the UTM longitude zone, 'S' is the UTM latitude zone, 'UU' is the 100,000m square identification, 83626 is the easting reference to 1m precision and 01432 is the northing reference to 1m precision.

MGRSRef

Methods are provided to query an MGRSRef object for its parameters. As MGRS references are related to UTM references, a toUTMRef() method is provided to convert an MGRSRef object into a UTMRef object. The reverse conversion can be made using the MGRSRef(UTMRef) constructor.

MGRSRef objects can be converted to LatLng objects using the toLatLng() method. The reverse conversion is made using the LatLng.toMGRSRef() method.

Some MGRS references use the Bessel 1841 ellipsoid rather than the Geodetic Reference System 1980 (GRS 1980), International or World Geodetic System 1984 (WGS84) ellipsoids. Use the constructors with the optional boolean parameter to be able to specify whether your MGRS reference uses the Bessel 1841 ellipsoid. Note that no automatic determination of the correct ellipsoid to use is made.

Important note: There is currently no support for MGRS references in polar regions north of 84°N and south of 80°S. There is also no account made for UTM zones with slightly different sizes to normal around Svalbard and Norway.

(c) 2006 Jonathan Stott

Created on 25-Feb-2006

Since:
1.1
Version:
1.1
Author:
Jonathan Stott

Field Summary
static int PRECISION_10000M
          Used to indicate a required precision of 10000m (10km).
static int PRECISION_1000M
          Used to indicate a required precision of 1000m (1km).
static int PRECISION_100M
          Used to indicate a required precision of 100m.
static int PRECISION_10M
          Used to indicate a required precision of 10m.
static int PRECISION_1M
          Used to indicate a required precision of 1m.
 
Constructor Summary
MGRSRef(int utmZoneNumber, char utmZoneChar, char eastingID, char northingID, int easting, int northing, int precision)
          Create a new MGRS reference object from the given paramaters.
MGRSRef(int utmZoneNumber, char utmZoneChar, char eastingID, char northingID, int easting, int northing, int precision, boolean isBessel)
          Create a new MGRS reference object from the given paramaters.
MGRSRef(java.lang.String ref)
          Create a new MGRS reference object from the given String.
MGRSRef(java.lang.String ref, boolean isBessel)
          Create a new MGRS reference object from the given String.
MGRSRef(UTMRef utm)
          Create a new MGRS reference object from the given UTM reference.
MGRSRef(UTMRef utm, boolean isBessel)
          Create a new MGRS reference object from the given UTM reference.
 
Method Summary
 int getEasting()
           
 char getEastingID()
           
 int getNorthing()
           
 char getNorthingID()
           
 int getPrecision()
           
 char getUtmZoneChar()
           
 int getUtmZoneNumber()
           
 boolean isBessel()
           
 LatLng toLatLng()
          Convert this MGRS reference to a latitude and longitude.
 java.lang.String toString()
          Return a String representation of this MGRS Reference to whatever precision this reference is set to.
 java.lang.String toString(int precision)
          Return a String representation of this MGRS reference to 1m, 10m, 100m, 1000m or 10000m precision.
 UTMRef toUTMRef()
          Convert this MGRS reference to an equivelent UTM reference.
 
Methods inherited from class uk.me.jstott.jcoord.CoordinateSystem
getDatum, setDatum
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PRECISION_10000M

public static final int PRECISION_10000M
Used to indicate a required precision of 10000m (10km).

See Also:
Constant Field Values

PRECISION_1000M

public static final int PRECISION_1000M
Used to indicate a required precision of 1000m (1km).

See Also:
Constant Field Values

PRECISION_100M

public static final int PRECISION_100M
Used to indicate a required precision of 100m.

See Also:
Constant Field Values

PRECISION_10M

public static final int PRECISION_10M
Used to indicate a required precision of 10m.

See Also:
Constant Field Values

PRECISION_1M

public static final int PRECISION_1M
Used to indicate a required precision of 1m.

See Also:
Constant Field Values
Constructor Detail

MGRSRef

public MGRSRef(UTMRef utm)
Create a new MGRS reference object from the given UTM reference. It is assumed that the UTMRef object is valid.

Parameters:
utm - a UTM reference.
Since:
1.1

MGRSRef

public MGRSRef(UTMRef utm,
               boolean isBessel)
Create a new MGRS reference object from the given UTM reference. It is assumed that this MGRS reference represents a point using the GRS 1980, International or WGS84 ellipsoids. It is assumed that the UTMRef object is valid.

Parameters:
utm - a UTM reference.
isBessel - true if the parameters represent an MGRS reference using the Bessel 1841 ellipsoid; false is the parameters represent an MGRS reference using the GRS 1980, International or WGS84 ellipsoids.
Since:
1.1

MGRSRef

public MGRSRef(int utmZoneNumber,
               char utmZoneChar,
               char eastingID,
               char northingID,
               int easting,
               int northing,
               int precision)
        throws java.lang.IllegalArgumentException
Create a new MGRS reference object from the given paramaters. It is assumed that this MGRS reference represents a point using the GRS 1980, International or WGS84 ellipsoids. An IllegalArgumentException is thrown if any of the parameters are invalid.

Parameters:
utmZoneNumber - the UTM zone number representing the longitude.
utmZoneChar - the UTM zone character representing the latitude.
eastingID - character representing the 100,000km easting square.
northingID - character representing the 100,000km easting square.
easting - easting in metres.
northing - northing in metres.
precision - the precision of the given easting and northing. Must be one of MGRSRef.PRECISION_1M, MGRSRef.PRECISION_10M, MGRSRef.PRECISION_100M, MGRSRef.PRECISION_1000M or MGRSRef.PRECISION_10000M.
Throws:
java.lang.IllegalArgumentException - if any of the given parameters are invalid.
Since:
1.1

MGRSRef

public MGRSRef(int utmZoneNumber,
               char utmZoneChar,
               char eastingID,
               char northingID,
               int easting,
               int northing,
               int precision,
               boolean isBessel)
        throws java.lang.IllegalArgumentException
Create a new MGRS reference object from the given paramaters. An IllegalArgumentException is thrown if any of the parameters are invalid.

Parameters:
utmZoneNumber - the UTM zone number representing the longitude.
utmZoneChar - the UTM zone character representing the latitude.
eastingID - character representing the 100,000km easting square.
northingID - character representing the 100,000km easting square.
easting - easting in metres.
northing - northing in metres.
precision - the precision of the given easting and northing. Must be one of MGRSRef.PRECISION_1M, MGRSRef.PRECISION_10M, MGRSRef.PRECISION_100M, MGRSRef.PRECISION_1000M or MGRSRef.PRECISION_10000M.
isBessel - true if the parameters represent an MGRS reference using the Bessel 1841 ellipsoid; false is the parameters represent an MGRS reference using the GRS 1980, International or WGS84 ellipsoids.
Throws:
java.lang.IllegalArgumentException - if any of the given parameters are invalid. Note that the parameters are only checked for the range of values that they can take on. Being able to create an MGRSRef object does not necessarily imply that the reference is valid.
Since:
1.1

MGRSRef

public MGRSRef(java.lang.String ref)
        throws java.lang.IllegalArgumentException
Create a new MGRS reference object from the given String. Must be correctly formatted otherwise an IllegalArgumentException will be thrown. It is assumed that this MGRS reference represents a point using the GRS 1980, International or WGS84 ellipsoids.

Parameters:
ref - a String to create an MGRS reference from.
Throws:
java.lang.IllegalArgumentException - if the given String is not correctly. formatted
Since:
1.1

MGRSRef

public MGRSRef(java.lang.String ref,
               boolean isBessel)
        throws java.lang.IllegalArgumentException
Create a new MGRS reference object from the given String. Must be correctly formatted otherwise an IllegalArgumentException will be thrown.

Parameters:
ref - a String to create an MGRS reference from.
isBessel - true if the parameters represent an MGRS reference using the Bessel 1841 ellipsoid; false is the parameters represent an MGRS reference using the GRS 1980, International or WGS84 ellipsoids.
Throws:
java.lang.IllegalArgumentException - if the given String is not correctly. formatted
Since:
1.1
Method Detail

toUTMRef

public UTMRef toUTMRef()
Convert this MGRS reference to an equivelent UTM reference.

Returns:
the equivalent UTM reference.
Since:
1.1

toLatLng

public LatLng toLatLng()
Convert this MGRS reference to a latitude and longitude.

Specified by:
toLatLng in class CoordinateSystem
Returns:
the converted latitude and longitude.
Since:
1.1

toString

public java.lang.String toString()
Return a String representation of this MGRS Reference to whatever precision this reference is set to.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of this MGRS reference to whatever precision this reference is set to.
Since:
1.1

toString

public java.lang.String toString(int precision)
Return a String representation of this MGRS reference to 1m, 10m, 100m, 1000m or 10000m precision.

Parameters:
precision - One of MGRSRef.PRECISION_1M, MGRSRef.PRECISION_10M, MGRSRef.PRECISION_100M, MGRSRef.PRECISION_1000M, MGRSRef.PRECISION_10000M.
Returns:
a String representation of this MGRS reference to the required precision.
Since:
1.1

getEasting

public int getEasting()
Returns:
the easting
Since:
1.1

getEastingID

public char getEastingID()
Returns:
the eastingID
Since:
1.1

isBessel

public boolean isBessel()
Returns:
isBessel
Since:
1.1

getNorthing

public int getNorthing()
Returns:
the northing
Since:
1.1

getNorthingID

public char getNorthingID()
Returns:
the northingID
Since:
1.1

getPrecision

public int getPrecision()
Returns:
the precision
Since:
1.1

getUtmZoneChar

public char getUtmZoneChar()
Returns:
the utmZoneChar
Since:
1.1

getUtmZoneNumber

public int getUtmZoneNumber()
Returns:
the utmZoneNumber
Since:
1.1