As I mentioned when I started the series of Practical Tools with Python, I thought; Just as before, it was that the feedbacks made as a result of the sharing will be evaluated and the solution for the problem will be developed and presented again. This is exactly what is the main factor in the emergence of this article. In a comment that my last share of this series, “Coordinate Transformation” received on Linkedin, it was mentioned about the problem of converting a coordinate belonging to MGRS (Military Grid Reference System) to WGS84 geographical coordinate equivalent.

First of all, I would like to thank Mr. Hüseyin Sefa HIZLI, who is working as a Meteorology Engineer at the 20th District 202th Branch Directorate of DSI, who commented on the sharing on Linkedin, for his feedback and valuable contributions. As mentioned in his comment, converting a coordinate of MGRS into WGS84 geographical coordinate is not done by many software. Although the software called Google Earth Pro, which is widely used today, offers MGRS support, it is necessary to deal with it one by one to make the conversion, which is a considerable waste of time. Based on this situation, I encoded a Python application called MGRS Converter so that this and vice versa can be done quickly in a batch. Let’s talk a little bit about what MGRS is before moving on to this tool.

What is MGRS?

The MGRS, the Military Grid Reference System, is the geographic coordinate standard used by NATO troops to locate the world. (For detailed information, see: https://en.wikipedia.org/wiki/Military_Grid_Reference_System )

MGRS Converter

Before I started coding the application of MGRS Converter, I came across the Python module named mgrs at https://pypi.org/project/mgrs/ when I searched whether there were any examples of this process done with Python over the internet. After installing this module on your computer with pip setup, it is possible to convert your wgs84 geographic coordinate to MGRS equivalent or your MGRS coordinate to WGS84 geographical equivalent. Only a simple example of how this process is done on the related page is illustrated with a simple example of how the transformation of a single point is made. At this point, I developed the MGRS Converter tool, which will enable mass conversion, similar to the Coordinate Converter application I mentioned in my previous article. In this way, you can quickly convert many WGS84 geographic or MGRS coordinates at hand.

To do this, you have to save and close the file by copying your existing coordinates to the “coordinate.txt” file in the same directory (your geographic coordinate pairs should be copied in longitude latitude and spacing between them). Then run the code written in Python in your compiler. Thus, each of the coordinates written in the “coordinate.txt” file, regardless of the MGRS or WGS84 geographical difference, will be calculated using the calculation method in the mgrs module and converted to its equivalent in the other coordinate reference system and the process will be completed in this way.

Github: https://github.com/hakankocaman/PratikPythonAraclari/blob/master/MGRS_Convertor.py

--

--