MGRS Coordinate Conversion for Python

1.5.4 · active · verified Thu Apr 16

The `mgrs` Python library (version 1.5.4) provides a simple `ctypes` wrapper around selected MGRS-related C functions from GeoTrans (version 2.4.2), an internal copy of which is included within the library. It facilitates conversions to and from Military Grid Reference System (MGRS) coordinates and decimal degrees (latitude/longitude), offering various precision levels. The library is actively maintained, with a recent release in February 2026.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the MGRS converter and perform common operations such as converting between latitude/longitude and MGRS, and between Degrees-Minutes-Seconds (DMS) strings and decimal degrees. Precision can also be controlled in `toMGRS()`.

from mgrs import MGRS

m = MGRS()

# Convert Latitude/Longitude to MGRS
latitude = 42.0
longitude = -93.0
mgrs_coords = m.toMGRS(latitude, longitude)
print(f"({latitude}, {longitude}) -> {mgrs_coords}")

# Convert MGRS to Latitude/Longitude
lat_lon_coords = m.toLatLon(mgrs_coords)
print(f"{mgrs_coords} -> {lat_lon_coords}")

# Convert DMS to Decimal Degrees
dms_str = '321942.29N'
dec_deg = m.dmstodd(dms_str)
print(f"{dms_str} -> {dec_deg}")

# Convert Decimal Degrees to DMS
d, minute, s = m.ddtodms(dec_deg)
print(f"{dec_deg} -> (D:{d}, M:{minute}, S:{s}))")

view raw JSON →