Package pygeodesy :: Module mgrs
[frames] | no frames]

Module mgrs

Military Grid Reference System (MGRS/NATO) references.

Military Grid Reference System (MGRS/NATO) classes Mgrs and MGRSError and functions parseMGRS and toMgrs.

Pure Python implementation of MGRS / UTM / UPS conversion functions using an ellipsoidal earth model, in part transcoded from JavaScript originals by (C) Chris Veness 2014-2016 published under the same MIT Licence**, see MGRS and Module mgrs.

The MGRS/NATO grid references provide geocoordinate references covering the entire globe, based on UTM and UPS projections.

MGRS references comprise a grid zone designation (GZD), a 100 km grid (square) tile identification, and an easting and northing (in meter). The GZD consists of a longitudinal zone (or column) number and latitudinal band (row) letter. Each zone (column) is 6 degrees wide and each band (row) is 8 degrees high, except the top one 'X' is 12 degrees tall.

See also the United States National Grid and Military Grid Reference System.


Version: 22.07.23

Classes
  Mgrs
Military Grid Reference System (MGRS/NATO) references, with method to convert to UTM coordinates.
  Mgrs4Tuple
4-Tuple (zone, digraph, easting, northing), zone and digraph as str, easting and northing in meter.
  Mgrs6Tuple
6-Tuple (zone, digraph, easting, northing, band, datum), zone, digraph and band as str, easting and northing in meter and datum a Datum.
Functions
 
parseMGRS(strMGRS, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Tran..., Mgrs=<class 'pygeodesy.mgrs.Mgrs'>, name='')
Parse a string representing a MGRS grid reference, consisting of "zoneBand, grid, easting, northing".
 
toMgrs(utmups, Mgrs=<class 'pygeodesy.mgrs.Mgrs'>, name='', **Mgrs_kwds)
Convert a UTM or UPS coordinate to an MGRS grid reference.
Variables
  __all__ = _ALL_LAZY.mgrs
Function Details

parseMGRS (strMGRS, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Tran..., Mgrs=<class 'pygeodesy.mgrs.Mgrs'>, name='')

 

Parse a string representing a MGRS grid reference, consisting of "zoneBand, grid, easting, northing".

Arguments:
  • strMGRS - MGRS grid reference (str).
  • datum - Optional datum to use (Datum).
  • Mgrs - Optional class to return the MGRS grid reference (Mgrs) or None.
  • name - Optional Mgrs name (str).
Returns:
The MGRS grid reference as Mgrs or if Mgrs is None as an Mgrs4Tuple(zone, digraph, easting, northing).
Raises:

Example:

>>> m = parseMGRS('31U DQ 48251 11932')
>>> str(m)  # '31U DQ 48251 11932'
>>> m = parseMGRS('31UDQ4825111932')
>>> repr(m)  # [Z:31U, G:DQ, E:48251, N:11932]
>>> m = mgrs.parseMGRS('42SXD0970538646')
>>> str(m)  # '42S XD 09705 38646'
>>> m = mgrs.parseMGRS('42SXD9738')  # Km
>>> str(m)  # '42S XD 97000 38000'
>>> m = mgrs.parseMGRS('YUB17770380')  # polar
>>> str(m)  # '00Y UB 17770 03800'

toMgrs (utmups, Mgrs=<class 'pygeodesy.mgrs.Mgrs'>, name='', **Mgrs_kwds)

 
Convert a UTM or UPS coordinate to an MGRS grid reference.

@arg utmups: A UTM or UPS coordinate (L{Utm}, L{Etm} or L{Ups]).
@kwarg Mgrs: Optional class to return the MGRS grid reference
             (L{Mgrs}) or C{None}.
@kwarg name: Optional B{C{Mgrs}} name (C{str}).
@kwarg Mgrs_kwds: Optional, additional B{C{Mgrs}} keyword
                  arguments, ignored if C{B{Mgrs} is None}.

@return: The MGRS grid reference as B{C{Mgrs}} or if
         C{B{Mgrs} is None} as an L{Mgrs6Tuple}C{(zone,
         digraph, easting, northing, band, datum)}.

@raise MGRSError: Invalid B{C{utmups}}.

@raise TypeError: If B{C{utmups}} is not L{Utm} nor L{Etm}
                  nor L{Ups}.

@example:

 >>> u = Utm(31, 'N', 448251, 5411932)
 >>> m = u.toMgrs()  # 31U DQ 48251 11932