Closed DanielJDufour closed 4 years ago
Just for the records ...
The result of the Go port of this library ...
$ ./ccordconv MGRStoLL 30NYF6799300000
30NYF6799300000 -> -0.59232825 0.00000000
... versus the result of this library:
30NYF6799300000 -> [ -0.5923237618590356, 0.000004519636471168305 ]
Awesome! How'd you do it?!
In my Go implementation I have totally remove the bbox logic. Maybe the source of the problem?
export function toPoint(mgrs) {
if (mgrs === '') {
throw new TypeError(`toPoint received a blank string`);
}
const bbox = UTMtoLL(decode(mgrs.toUpperCase()));
if (bbox.lat && bbox.lon) {
return [bbox.lon, bbox.lat];
}
return [(bbox.left + bbox.right) / 2, (bbox.top + bbox.bottom) / 2];
}
Some test output (in mgrs.js) shows this:
UTMtoLL(utm) ...
utm : {
easting: 767993,
northing: 0,
zoneLetter: 'N',
zoneNumber: 30,
accuracy: 1
}
result : {
top: 0.00000903927294233661,
right: -0.5923192724786963,
bottom: 0,
left: -0.5923282512393748
}
mgrs -> lon/lat : 30NYF6799300000 -> [ -0.5923237618590356, 0.000004519636471168305 ]
The calculated utm value is correct. But it seems that the bbox calculation is applied in order to get the lon lat values. And that results in "0.000004519636471168305" and not in "0.0".
The calculated lon lat values are looking good for me:
lon : -0.5923282512393748
lat : 0
@Klaus-Tockloth , thank you! :-) That's a great find! I think with that information I can fix this library.
I'm closing this PR as NGA has updated their MGRS calculation to use the center of the box (which is what this library was doing anyway). In other words, zero northing should not be returning a zero now, but instead return a latitude of half the precision. Please see this PR for more context: https://github.com/proj4js/mgrs/pull/60 And feel free to comment or open another issue if you feel I have missed something. Thank you!
toPoint(30NYF6799300000)
returns0.000004519636471168305
for latitude where it should return0
. I understand that this is consistent with the imprecision brought on by floating-point arithmetic, but I will try to see if I can find a way to improve precision.