hobuinc / mgrs

Python MGRS library
https://pypi.python.org/pypi/mgrs
MIT License
111 stars 36 forks source link

Not getting correct lat lon #40

Open ruffyleaf opened 1 year ago

ruffyleaf commented 1 year ago

Hi, I'm getting a wrong Lat Lon for this MGRS "04QEJ 97987 90670".

The correct lat/lon is "21.61643, -158.05325", but I'm getting

"20.79987937710965, -158.99999999999997"

Is there something that I am missing?

topowright22 commented 1 year ago

I am running into some challenges as well and I noticed that this gets better when you remove the spaces in the coordinate

### Test
mgrs_sample_coord = "04QEJ9798790670"
mrgs_to_dd(mgrs_sample_coord)    

output ('21.616', '-158.053')

juve commented 1 year ago

Whitespace causes it to ignore characters after a valid MGRS:

>>> mgrs.MGRS().toLatLon("17SMB8287460719 is an Odd place")
(37.593380583269465, -81.19399653530921)
>>> mgrs.MGRS().toLatLon("Bad company, I can't deny\nBad, bad company, 'til the day I die")
(-81.90657174926099, 180.0)
hobu commented 1 year ago

the python extension simply passes down its entire input string to the mgrs C code, so if we want string sanitation before that, we're going to have to add it python side. I had previously not done anything there so as to not take any responsibility. The MGRS C code has not been updated since it was first copied into this library 10+ years ago...

AnthonyMensier commented 1 year ago

Hey @hobu - I believe it would be useful to update the README with some examples of the MGRSPrecision parameter.

I suggest the following edits:

You can also control the precision of the MGRS grid with the MGRSPrecision arguments in .toMGRS(). MGRSPrecision takes an integer as input, ranking from 0 to 5, 5 being the most precise conversion.

Example

5 vs 0 MGRSPrecision setting::

>>> m = mgrs.MGRS()
>>> c = m.toMGRS(latitude, longitude, 5)
>>> c
'15TWG0000049776'

>>> m = mgrs.MGRS()
>>> c = m.toMGRS(latitude, longitude, 0)
>>> c
'15TWG'
hobu commented 1 year ago

I believe it would be useful to update the README with some examples of the MGRSPrecision parameter.

Please make a pull request proposing something.