What's the best way to convert MGRS to UTM XY (value to value)

4503
3
08-22-2017 02:50 PM
Labels (1)
TimBarnes
Occasional Contributor III

I'm updating my script which reads a spreadsheet of values including coordinates but the spreadsheet is not formatted as a table par se. Instead of projected X and Y coordinates, I'd like to move to the user inputting a single MGRS value for each coordinate/position required.

This requires conversion back into X and Y values for the actual processing (i.e. arcpy.point(x,y)).

Unfortunately, the arcpy.ConvertCoordinateNotation requies a input table and gives an output featureclass and I'm dealing with discreet values. In other words, I just want to give an MGRS (string) and get a UTM X (long) & Y (long) from arcpy....the tool isn't designed to work at that fundamental level which seems odd.

So, working through that, it seems as if, given a single MGRS value I need to

  1. create a table (in memory)
  2. add an mgrs field
  3. create a cursor on that table
  4. insert a row with the MGRS value
  5. run convert coordinate notation tool, outputting a featureclass
  6. create another cursor on that featureclass
  7. read the row to get the X and Y values.

....and that's for a single conversion.

So my question is: "Is that the best way"?! It seems very convoluted.

3 Replies
MelitaKennedy
Esri Notable Contributor

If you're willing to use ArcObjects check out IConversionNotation or IConversionMGRS

TimBarnes
Occasional Contributor III

I'm keeping it within python as I also use this script as both a toolbox tool and web geoprocessing service.

The method I outlined above does work and is fast enough for what I'm doing...it just seems really convoluted compared to say

utmCoords = arcpy.convertCoordinateNotation(input coordinates = [x,y],input format = 'MGRS', output format = 'UTM') returning a tuple utmCoords[0] = <x coord> utmCoords[1] = <y coordinate> or string etc?

deleted-user-JTyWy9b20ETO
New Contributor II

I had a similar need to convert single points between MGRS and lat long 

I found this package does the trick: mgrs · PyPI.  It converts single points between MGRS and UTM or Lat Long.

I had to pip install mgrs, since the conda package manager only wants to support 'optimized' packages.  When I installed the conda package from https://anaconda.org/conda-forge/mgrs, using conda on the command line, the package wanted to make a lot of changes to the default core python environment shipped with ArcGIS Pro 2.5. 

After installing the pip package to a cloned environment,  I needed to reactivate the default environment and then switch back to the cloned environment before the package was recognized.