proj4js / mgrs

Utility for converting between WGS84 lat/lng and MGRS coordinates
MIT License
105 stars 45 forks source link

Latitude Zone Out of Range #30

Closed pjobson closed 5 years ago

pjobson commented 5 years ago

Valid Latitude Zone values include: CDEFGHJKLMNPQRSTUVWX

 forward([-90,-180], 5);
 // Returns invalid reference: 16ZHF3397995930
 forward([90, 180], 5);
 // Returns invalid reference: 46ZHE3397995930
DanielJDufour commented 5 years ago

Hi, @pjobson . A new maintainer here. Thank you for bringing this to our attention. mgrs takes input in [longitude, latitude] arrays, so the inputs mentioned above in [lat, lon] should be invalid. I created an issue to address this.

I believe the reason you are seeing Z and H are because mgrs thinks that the coordinates are in the polar regions and is using Universal Polar Stereographic. Let me know if I missed anything :-)

Reference: https://en.wikipedia.org/wiki/Military_Grid_Reference_System#Polar_regions

DanielJDufour commented 5 years ago

Actually, my previous comment was partially wrong. This library doesn't support Universal Polar Stereographic and the Z is being used as an error flag: https://github.com/proj4js/mgrs/blob/master/mgrs.js#L291

Apologies for the confusion.

pjobson commented 5 years ago

No problem! Thanks for getting back to me. Prior to messing with your library I had pretty much zero knowledge of MGRS. I thought that was a bit odd until I read the article on Irish Transverse Mercator (ITM) on wikipedia.

DanielJDufour commented 5 years ago

Fixed by https://github.com/proj4js/mgrs/pull/36 which throws an error for points in polar regions

I will keep the issue open about adding support for polar regions: https://github.com/proj4js/mgrs/issues/33