mgrs icon indicating copy to clipboard operation
mgrs copied to clipboard

inverse does not return bbox for 100km grid zone

Open gregsadetsky opened this issue 7 years ago • 10 comments

Calling mgrs.inverse with a 100km grid zone identifier, such as 16RGU, returns the same latitude, longitude twice instead of a bounding box.

I believe that this is by design -- see https://github.com/proj4js/mgrs/blob/master/mgrs.js#L78

Is there a particular reason why such grid identifiers are not converted into bounding boxes?

Thanks!

gregsadetsky avatar Oct 17 '18 16:10 gregsadetsky

This issue is the reason that I cannot use this project. Well that and I also cannot get a top level grid zone only by the first two letters.

monkeytroy avatar Nov 18 '19 15:11 monkeytroy

Hi, @gregsadetsky and @monkeytroy . Thanks for flagging that this is still a problem. I'll work on a solution and hopefully have it done within a week. Thanks!

DanielJDufour avatar Nov 20 '19 04:11 DanielJDufour

Any ETA on when this will be fixed?

chcolemanjr avatar Jan 29 '20 00:01 chcolemanjr

Hi, @chcolemanjr . I'm sorry for the delay. I'll try to have a fix by the end of next week (if not sooner). I'll post here and tag you when that is complete.

DanielJDufour avatar Jan 29 '20 19:01 DanielJDufour

@DanielJDufour Thanks for response and effort. I appreciate it. While you're looking at the inverse() function could you do a bounds check on the returned lat and longs? I noticed quite a few longitudes coming back with values greater than 180 and less than -180. Thanks again!

chcolemanjr avatar Jan 30 '20 14:01 chcolemanjr

Will do. Could you share some of these values returning erroneous bounds, so I can add that to the tests?

DanielJDufour avatar Jan 30 '20 14:01 DanielJDufour

@DanielJDufour Sure. Here you go:

input mgrs: 1CAA returned from inverse(): -188.50987762588105 -71.75574866634604 -188.50987762588105 -71.75574866634604

input mgrs: 56CAA returned from inverse(): 193.28146856805336 -72.8415504450606 193.28146856805336 -72.8415504450606

input mgrs: 59CAA returned from inverse(): 202.73386440303392 -69.22888726751151 202.73386440303392 -69.22888726751151

input mgrs: 60CAA returned from inverse(): 192.09223094379075 -76.11955480636547 192.09223094379075 -76.11955480636547

input mgrs: 1DAA returned from inverse(): -188.50987762588105 -71.75574866634604 -188.50987762588105 -71.75574866634604

input mgrs: 59DAA returned from inverse(): 202.73386440303392 -69.22888726751151 202.73386440303392 -69.22888726751151

input mgrs: 60DAA returned from inverse(): 183.86206214277752 -58.45661355190297 183.86206214277752 -58.45661355190297

input mgrs: 1EAA returned from inverse(): -183.1047976395489 -53.99291942689445 -183.1047976395489 -53.99291942689445

input mgrs: 59EAA returned from inverse(): 188.87806686863846 -52.78874996684672 188.87806686863846 -52.78874996684672

input mgrs: 60EAA returned from inverse(): 183.86206214277752 -58.45661355190297 183.86206214277752 -58.45661355190297

input mgrs: 1FAA returned from inverse(): -183.1047976395489 -53.99291942689445 -183.1047976395489 -53.99291942689445

input mgrs: 59FAA returned from inverse(): 188.87806686863846 -52.78874996684672 188.87806686863846 -52.78874996684672

input mgrs: 60FAA returned from inverse(): 181.72363045788765 -40.55415972586964 181.72363045788765 -40.55415972586964

input mgrs: 1GAA returned from inverse(): -181.4402761156065 -36.062361996833644 -181.4402761156065 -36.062361996833644

input mgrs: 59GAA returned from inverse(): 184.1798329312292 -35.41600726991151 184.1798329312292 -35.41600726991151

input mgrs: 60GAA returned from inverse(): 181.72363045788765 -40.55415972586964 181.72363045788765 -40.55415972586964

input mgrs: 1HAA returned from inverse(): -181.4402761156065 -36.062361996833644 -181.4402761156065 -36.062361996833644

input mgrs: 59HAA returned from inverse(): 184.1798329312292 -35.41600726991151 184.1798329312292 -35.41600726991151

input mgrs: 60HAA returned from inverse(): 181.72363045788765 -40.55415972586964 181.72363045788765 -40.55415972586964

input mgrs: 1JAA returned from inverse(): -180.77735832101328 -18.051740497996235 -180.77735832101328 -18.051740497996235

input mgrs: 59JAA returned from inverse(): 182.26050842477588 -17.76056141770849 182.26050842477588 -17.76056141770849

input mgrs: 60JAA returned from inverse(): 180.8885179770934 -22.559763789039238 180.8885179770934 -22.559763789039238

input mgrs: 1KAA returned from inverse(): -180.77735832101328 -18.051740497996235 -180.77735832101328 -18.051740497996235

input mgrs: 59KAA returned from inverse(): 182.26050842477588 -17.76056141770849 182.26050842477588 -17.76056141770849

input mgrs: 60KAA returned from inverse(): 180.8885179770934 -22.559763789039238 180.8885179770934 -22.559763789039238

input mgrs: 60LAA returned from inverse(): 180.603447968944 -4.5145965610339385 180.603447968944 -4.5145965610339385

input mgrs: 60MAA returned from inverse(): 180.603447968944 -4.5145965610339385 180.603447968944 -4.5145965610339385

input mgrs: 60NAA returned from inverse(): 180.69450574002454 13.541119562220727 180.69450574002454 13.541119562220727

input mgrs: 1PAA returned from inverse(): -180.77735832101328 18.051740497996235 -180.77735832101328 18.051740497996235

input mgrs: 59PAA returned from inverse(): 182.26050842477588 17.76056141770849 182.26050842477588 17.76056141770849

input mgrs: 60PAA returned from inverse(): 180.69450574002454 13.541119562220727 180.69450574002454 13.541119562220727

input mgrs: 1QAA returned from inverse(): -180.77735832101328 18.051740497996235 -180.77735832101328 18.051740497996235

input mgrs: 59QAA returned from inverse(): 182.26050842477588 17.76056141770849 182.26050842477588 17.76056141770849

input mgrs: 60QAA returned from inverse(): 181.21332730451644 31.565646188641153 181.21332730451644 31.565646188641153

input mgrs: 1RAA returned from inverse(): -181.4402761156065 36.062361996833644 -181.4402761156065 36.062361996833644

input mgrs: 59RAA returned from inverse(): 184.1798329312292 35.41600726991151 184.1798329312292 35.41600726991151

input mgrs: 60RAA returned from inverse(): 181.21332730451644 31.565646188641153 181.21332730451644 31.565646188641153

input mgrs: 1SAA returned from inverse(): -181.4402761156065 36.062361996833644 -181.4402761156065 36.062361996833644

input mgrs: 59SAA returned from inverse(): 184.1798329312292 35.41600726991151 184.1798329312292 35.41600726991151

input mgrs: 60SAA returned from inverse(): 181.21332730451644 31.565646188641153 181.21332730451644 31.565646188641153

input mgrs: 1TAA returned from inverse(): -183.1047976395489 53.99291942689445 -183.1047976395489 53.99291942689445

input mgrs: 59TAA returned from inverse(): 188.87806686863846 52.78874996684672 188.87806686863846 52.78874996684672

input mgrs: 60TAA returned from inverse(): 182.52792431499915 49.520335070002616 182.52792431499915 49.520335070002616

input mgrs: 1UAA returned from inverse(): -183.1047976395489 53.99291942689445 -183.1047976395489 53.99291942689445

input mgrs: 59UAA returned from inverse(): 188.87806686863846 52.78874996684672 188.87806686863846 52.78874996684672

input mgrs: 60UAA returned from inverse(): 182.52792431499915 49.520335070002616 182.52792431499915 49.520335070002616

input mgrs: 1VAA returned from inverse(): -188.50987762588105 71.75574866634604 -188.50987762588105 71.75574866634604

input mgrs: 59VAA returned from inverse(): 202.73386440303392 69.22888726751151 202.73386440303392 69.22888726751151

input mgrs: 60VAA returned from inverse(): 186.33498896597143 67.34501697493593 186.33498896597143 67.34501697493593

input mgrs: 1WAA returned from inverse(): -188.50987762588105 71.75574866634604 -188.50987762588105 71.75574866634604

input mgrs: 59WAA returned from inverse(): 202.73386440303392 69.22888726751151 202.73386440303392 69.22888726751151

input mgrs: 60WAA returned from inverse(): 186.33498896597143 67.34501697493593 186.33498896597143 67.34501697493593

chcolemanjr avatar Jan 31 '20 04:01 chcolemanjr

Thank you @chcolemanjr . I'll look into it. As a fyi, NGA recently changed their MGRS calculations to use the centroid per "Fixed the truncation of MGRS coordinates by adding one-half the precision in MGRS to UTM conversions" (https://earth-info.nga.mil/GandG/update/index.php?action=home). This will require a re-write of some of the code, including the bounding box calculation. Unfortunately, I can't guarantee when this will be done. I'm definitely open to PRs if people can provide them.

DanielJDufour avatar Jan 31 '20 18:01 DanielJDufour

Hi I was planning on using this library but cant due to the issues above, is there ever going to be a fix for this or if not are there any resources youd recommend on how to fix it so I could make a PR?

martejj avatar Nov 22 '21 05:11 martejj

The fix is now available on a branch, please consult https://github.com/proj4js/mgrs/pull/68 or just grab the new version of mgrs.js (pre-built) here: https://github.com/proj4js/mgrs/blob/a67b28ec0df248d2ab524dffddb67401bc26960d/mgrs.js

Because so many people use this library, I need to write some tests that cover the 100k use cases (including toPoint) because I think this code may have indirect untested impact on the results of other function calls.

DanielJDufour avatar Nov 22 '21 14:11 DanielJDufour