Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Conversion of MGRS to lat/long and vice versa #85

Open
Stargator opened this issue Jun 1, 2023 · 2 comments
Open

Inconsistent Conversion of MGRS to lat/long and vice versa #85

Stargator opened this issue Jun 1, 2023 · 2 comments

Comments

@Stargator
Copy link

I have been using mgrs 1.0.0 and just upgraded to 2.0.0 to see if this recently discovered issue was resolved.

The issue remains in 2.0.0.

  1. When I convert lat and lon from [12, 12] to MGRS, the MGRS value is 33PSP7328528333. I am passing an accuracy of 5, ex forward([12, 12], 5).

  2. When converting MGRS to latLong, using the same MGRS above (33PSP73282833), the lat and lon return as [12.000002866546339, 12.000000805373205]. Ex: toPoint("33PSP73282833")

I don't know why this is happening.

For comparison of expectations, using legallandconverter.com I can entered lat 12 and lon 12 and get 33PSP7328528333.

And in reverse, if I give 33PSP7328528333, the website returns lat 12 and lon 12. So it's consistent when using the highest level of precision afforded by MGRS.

If I were to guess, I would say that the toPoint method is using a less precise conversion even when the MGRS string is as precise as possible.

@Tronald
Copy link

Tronald commented Jun 1, 2023

MGRS coordinates are truncated during conversion to start at the bottom left corner of the square per spec. A centimeter MGRS conversion from the specified coordinates actually yields a more accurate result of 33P SP 73285.4087 28333.18345

As the centimeter precision is stripped from standard MGRS coordinates, you will often experience shifting when doing back and forth conversions to lat/long.

legallandconverter.com yields a correct result as the decimal precision of the signed coordinate only goes out 5 places. If you look at your results, the precision of your lat long coordinates changes at 6 places.

12.00000
12.000002866546339

With that said, the conversion back to lat/long should actually be in the 11.999999 11.999999 range as evidenced by the DMS coordinates provided from legallandconverter.com, CoordinateSharp and EarthPoint.

So while it is normal for such shifting to occur, one of the devs may want to chime in if the conversion is in fact shifting the wrong way.

@DanielJDufour
Copy link
Collaborator

DanielJDufour commented Jun 1, 2023

Thank you @Stargator for raising this important issue and thank you @Tronald for the excellent explanation. Unfortunately, I don't have a quick answer for you regarding the apparently imprecise conversion from MGRS to Lat/Long.

I think the next step would be to check what result NGA GEOTRANS gives and take if from there.

Although I don't think it explains everything going on here, this library does use JavaScript's built-in arithmetic, so it is susceptible to floating point arithmetic imprecision. A long-term goal of mine, is to provide a more precise alternative in pure-JavaScript that either uses symbolic math or a higher precision. Absent funding, we are still probably a few years away from that, but just wanted to let you know I recognize the problem and it is on my radar :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants