Class: Mgrs

mgrs~Mgrs(zone, band, e100k, n100k, easting, northing, datumopt)

Military Grid Reference System (MGRS/NATO) grid references, with methods to parse references, and to convert to UTM coordinates.

Constructor

new Mgrs(zone, band, e100k, n100k, easting, northing, datumopt)

Creates an Mgrs grid reference object.
Parameters:
Name Type Attributes Default Description
zone number 6° longitudinal zone (1..60 covering 180°W..180°E).
band string 8° latitudinal band (C..X covering 80°S..84°N).
e100k string First letter (E) of 100km grid square.
n100k string Second letter (N) of 100km grid square.
easting number Easting in metres within 100km grid square.
northing number Northing in metres within 100km grid square.
datum LatLon.datums <optional>
WGS84 Datum UTM coordinate is based on.
Source:
Throws:
Invalid MGRS grid reference.
Type
RangeError
Example
import Mgrs from '/js/geodesy/mgrs.js';
  const mgrsRef = new Mgrs(31, 'U', 'D', 'Q', 48251, 11932); // 31U DQ 48251 11932

Methods

(static) parse(mgrsGridRef) → {Mgrs}

Parses string representation of MGRS grid reference. An MGRS grid reference comprises (space-separated) - grid zone designator (GZD) - 100km grid square letter-pair - easting - northing.
Parameters:
Name Type Description
mgrsGridRef string String representation of MGRS grid reference.
Source:
Throws:
Invalid MGRS grid reference.
Type
Error
Returns:
Mgrs grid reference object.
Type
Mgrs
Example
const mgrsRef = Mgrs.parse('31U DQ 48251 11932');
  const mgrsRef = Mgrs.parse('31UDQ4825111932');
  //  mgrsRef: { zone:31, band:'U', e100k:'D', n100k:'Q', easting:48251, northing:11932 }

toString(digitsopt) → {string}

Returns a string representation of an MGRS grid reference. To distinguish from civilian UTM coordinate representations, no space is included within the zone/band grid zone designator. Components are separated by spaces: for a military-style unseparated string, use Mgrs.toString().replace(/ /g, ''); Note that MGRS grid references get truncated, not rounded (unlike UTM coordinates); grid references indicate a bounding square, rather than a point, with the size of the square indicated by the precision - a precision of 10 indicates a 1-metre square, a precision of 4 indicates a 1,000-metre square (hence 31U DQ 48 11 indicates a 1km square with SW corner at 31 N 448000 5411000, which would include the 1m square 31U DQ 48251 11932).
Parameters:
Name Type Attributes Default Description
digits number <optional>
10 Precision of returned grid reference (eg 4 = km, 10 = m).
Source:
Throws:
Invalid precision.
Type
RangeError
Returns:
This grid reference in standard format.
Type
string
Example
const mgrsStr = new Mgrs(31, 'U', 'D', 'Q', 48251, 11932).toString(); // 31U DQ 48251 11932

toUtm() → {Utm}

Converts MGRS grid reference to UTM coordinate. Grid references refer to squares rather than points (with the size of the square indicated by the precision of the reference); this conversion will return the UTM coordinate of the SW corner of the grid reference square.
Source:
Returns:
UTM coordinate of SW corner of this MGRS grid reference.
Type
Utm
Example
const mgrsRef = Mgrs.parse('31U DQ 48251 11932');
  const utmCoord = mgrsRef.toUtm(); // 31 N 448251 5411932