8

How can I convert Military Grid Reference System (MGRS) to lat/lon or UTM?

5 Answers 5

8

I had to write code to convert MGRS to LL last year, however, I am unable to post the code. What I can post though are the two main resources I utilized while writing the code:

US Military Grid Reference System description, published by NGA and the related Appendix and an Online MGRS to LL Converter to check your results as you are coding.

There is also GeographicLib, an open-source library that has code for MGRS conversions and is licensed under MIT. You'll need to look at the GeographicLib::MGRS class, and the MGRS.hpp and MGRS.cpp files if you need to look at the code.

If you can elaborate more on whether you are looking for code, a library, or a utility to convert one or more coordinates, you'll get better answers.

2
  • Thank you for the quick response! Basically I am looking for some formula/code to convert MGRS to lat long or UTM. I am working with Silverlight API and I want to locate the point based on MGRS input.
    – Rahul
    Commented Oct 5, 2011 at 18:25
  • 2
    My suggestion then is to look at GeographicLib and either compile the code as a DLL and use the DLL + PInvoke to access the methods from C#, or convert the relevant C++ code to C# (2nd option would be my preferred route). Of course, assuming your project is compatible with a MIT style license. Commented Oct 5, 2011 at 18:28
3

GDAL has a silent implementation of MGRS.

You can find the source code here:

https://svn.osgeo.org/gdal/trunk/gdal/frmts/nitf/mgrs.c

3

If someone needs this in JavaScript...

Probably worth linking to this question, which includes a link to a GPL'd (unfortunately; LGPL would have been more universally useful) JavaScript lib that'll do this.

I should probably add that the library is, more accurately, USNG, which is apparently very closely related to MGRS but not exactly the same.

When referenced to NAD 83 or WGS 84, USNG values are equivalent to Military Grid Reference System (MGRS) values. The difference in these two systems is that USNG referenced to NAD27 uses the MGRS WGS 84 scheme of 100,000m Square Identifications...

(from the above link to The American Surveyor)

It looks like OpenLayers lets you do it as well -- an example of it in a production environment (with an MIT-flavor license) can be found here.

That link is now (Mar 2023) dead and is not archived at archived.org. This project may be a decent replacement and is also MIT licensed.:

https://github.com/codice/usng.js/

2

There is a nice online coordinates converter for WGS84, UTM, CH1903, UTMREF(MGRS), Gauß-Krüger, NAC, W3W: https://coordinates-converter.com/en/

0

You could also use Python to convert MGRS to lat/long and vice versa. Using the library pyproj you can convert a given MGRS tile (say, WGS84) as follows:

import pyproj

geod = pyproj.Geod(ellps='WGS84')

lat_min, lon_min = mgrs_object.toLatLon(mgrs_id)

x_var = geod.line_length([lon_min, lon_min], [lat_min, lat_min + 1])
y_var = geod.line_length([lon_min, lon_min + 1], [lat_min, lat_min])

lat_max = lat_min + mgrs_tile_edge_size / x_var
lon_max = lon_min + mgrs_tile_edge_size / y_var

lat_min, lon_min, lat_max, lon_max then give the corners of the tile in lon/lat coordinates.

For more background information you can have a look at this blog post.

1
  • The mgrs Python module is needed in order to convert to/from MGRS coordinates, not the pyproj module. Commented Jan 23 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.