1

I'm making an MGRS overlay plugin for leaflet. To help with this, I've been using some of the leaflet mosue coordinate plugins. But they have occasional math errors. So I want to write some unit tests for their conversion code. The first step is having test data.

I ran Geotrans 3.7 on a set of test Lat/Lng data to get UTM, MGRS, and USNG. Following the basic file processing section of the user guide: running the GUI, file open, open the Gold Data map_proj/WGS84/Lat_Lon.csv, and selecting the output coordinate system, and saving.

I ran a diff on the MGRS and USNG data, and it showed a difference.

$ diff mgrs.dat usng.dat 
1c1
< COORDINATES: Military Grid Reference System (MGRS)
---
> COORDINATES: United States National Grid (USNG)
100c100
< 40REU0000018785
---
> 40RDU9999918785
208c208
< 31XDP6500529005
---
> ZAA0000033272
258c258
< 41XMP6500529005
---
> ZHD7740366636

In Geotrans, I can convert 40RDU9999918785 USNG -> Lng/Lat(57E, 30N) -> USNG, and it results in 40REU0000018785, which is 10 meters away. (It's also the coordinate given for MGRS)

ZAA0000033272 USNG -> Lng/Lat(0E 84N) -> USNG results in the same thing, but 31XDP6500529005 MGRS -> Lng/Lat is 84 0 0.0N 0 0 0.1W

So GeoTrans seems to be using different algorithms for MGRS and USNG, which is odd, as with WGS 84, they're identical.

So where should I go for example data I can trust, so I can evaluate/fix existing converters, or worst case write my own?

github.com/proj4js/mgrs(Can someone else edit this to be a link, "You need at least 10 reputation to post more than 2 links") looks reasonable, but it doesn't support the UPS part.

Update:

So using GeographicLibs GeoConvert (version 1.45, which was in the debian repos)

$ tail -n +13 Lat_Lon.csv | GeoConvert -m > mgrs.dat
$ tail -n +13 Lat_Lon.csv | GeoConvert -u > utm.dat

Differences between Geotrans and GeographicLib MGRS are as follows:

$ diff mgrs.dat mgrsGEOTRANS.dat
203c203
< ZAA0000033272
---
> 31XDP6500529005
253c253
< ZHD7740366636
---
> 41XMP6500529005

So for the first point, which is 84,0, converting back(with GeoConvert) gives

GeoConvert: 84.00000 0.00004
GeoTrans: 84.00000 0.00001

Second point is 84,60;

GeoConvert: 84.00000 60.00004
GeoTrans: 84.00000 60.00001

GeoConvert will do UTM/UPS at once, while Geotrans just gives Error: Output Universal Transverse Mercator (UTM): Latitude out of range, so I didn't compare those.

So my question becomes, can I just trust the GeoConvert values as perfect and correct, or should I use the two values from GeoTrans?

  • How are you using GeoTrans? The API has different options for resolution, so make sure you are using the correct one(s) – BradHards Dec 2 '16 at 21:41
  • @BradHards I edited the question to explain my usage, I didn't have any resolution options, as I just used the GUI not the API. – mtfurlan Dec 2 '16 at 21:54
  • The GUI has a precision tab under Options->Format. What do you have set? That said, I do see the same thing (and I'd expect accuracy to about ~1m). Geographiclib might be a better option. – BradHards Dec 2 '16 at 23:08
  • @BradHards I've tried GeographicLib, and I just want to confirm you(or someone else, but I haven't always had the best of luck with aging questions...) think my values are now good. – mtfurlan Dec 5 '16 at 16:04
1

For converting latlng <==> utm/usng/mgrs did you consider using the open source javascript that is currently maintained by Larry Moore? The js file with the code includes comments showing the code's history and contributors.

Start here. http://dhost.info/usngweb/ Open the map and go to near the bottom of the source code. The file you want is usng.js

I am using that code for coodinate conversion in Gmap4 and it works fine. https://mappingsupport.com/p/gmap4.php?usng=11S_KB_7217_8062&tilt=off&z=14&t=t4

  • Thank you for the suggestion, but on that site it says "DO NOT depend on this application around the prime meridian, international dateline, or in the areas of Norway or Svalbard." I was trying to get a set of code that deals with all exceptions. – mtfurlan Dec 27 '16 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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