MGRS Conversion Issue
See original GitHub issueHi 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:
- Created 4 years ago
- Comments:7 (4 by maintainers)
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).
Fixed in v2.2.1.