question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MGRS Conversion Issue

See original GitHub issue

Hi everyone,

I noticed that for a latitude of 64 degrees, the conversion from geodetic to MGRS is correct, but the conversion back will fail. The range of failure for latitude is 64 <= x < 64.03.

E.g. From: https://www.movable-type.co.uk/scripts/latlong-utm-mgrs.html

Input: Lat/Long

Lat/Long: 64.00078N, 171.45995W UTM: 02 N 477504 7097182 MGRS: 02W MR 77503 97182

Input: MGRS

Lat/Long: 81.92899585N, 172.43540147W UTM: 02 N 477503 9097182 MGRS: 02W MR 77503 97182

The issue is the value of northing of UTM, which is 2e6 off.

In my local copy I get around this by rounding the integer component of the MGRS letter offset added to northing to 5 significant integer digits, by changing:

while (n2M + n100kNum + this.northing < nBand) n2M += 2000e3;

To:

while (Math.round((n2M + n100kNum + this.northing) / 1e5) * 1e5 < nBand) n2M += 2000e3;

Is this an acceptable solution?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisvenesscommented, Feb 8, 2020

This is a fundamental aspect of the operation of UTM and MGRS.

To the best of my understanding, UTM coordinates conventionally get rounded, whereas MGRS references conventionally get truncated.

For the coordinate you give, the MGRS easting (within the 100km grid square) is 77503.623645 (477503.623645 for the UTM easting, from the central meridian). To 1-metre precision, these get truncated/rounded to 77503 & 477504.

This fundamental difference in approach to UTM coordinates and MGRS references means that round-trip conversions can never but achieved at library level; it has to be an application function to resolve the differences.

(I take it you are referring to eastings rather than northings).

0reactions
chrisvenesscommented, Apr 22, 2020

Fixed in v2.2.1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error during MGRS conversion for large latitudes
I suspect that conversion actually goes LatLng <==> UTM <==> MGRS. Since UTM is defined as valid for latitudes from 80°S to 84°N, ......
Read more >
MGRS Coordinates not saving - Bugs and Problems
- Select one of the MGRS steerpoints (21 through 25). - Convert it to MGRS with dobber SEQ. - Dobber down to GRID,...
Read more >
Understanding and converting MGRS coordinates in Python
In this post I show how MGRS (and UTM) work and how to use the mgrs library from python to convert from MGRS...
Read more >
Convert between Latitude/Longitude & UTM coordinates
Hence the UTM coordinate 31 N 303760 5787415 is equivalent to an MGRS grid reference of 31U CT 03760 87415. Depending on the...
Read more >
Military Grid Reference System - Legal Land Converter
MGRS / USNG to Latitude and Longitude · Latitude and Longitude to MGRS / USNG · United States National Grid (USNG) - Grid...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found