I have to convert a coordinate from UTM to MGRS. I think I have the most of it covered, but I have some difficulties to calculate the correct Latitude-band. How can I decide which band the coordinate has?
1 Answer
I use:
zone = math.floor ((lon + 180.0) / 6) + 1
Bear with me on that, and I'll check my library
So if
lon = -35
lat = 35
Then zone will be 25, which I think is correct. Try it and let me know if it works for you.
There is also:
andrewlesley.freeserve.co.uk/gps/convertr/UTM-MGRS.html
I am sure you can get into the JS and use the code.
var UTMzdlChars="CDEFGHJKLMNPQRSTUVWXX";
function UTMzdl(latDeg)
{
if(-80<=latDeg&&latDeg<=84)
{
return UTMzdlChars.charAt(Math.floor((latDeg+80)/8));
}else
{
//Not normally reached
alert("No zdl: UTM is not valid for Lat "+latDeg);
return "";
}
}
-
1Thank you, but I already have the zone. What I need is the Latitude-band, thats a letter. It is normally told together with the zone, i.e. 32V. I need to determine the V-part.– MnementhCommented Oct 12, 2011 at 10:36
-
1I found this: andrewlesley.freeserve.co.uk/gps/convertr/UTM-MGRS.html and I am sure you can crack into their js and get the functions out.– HairyCommented Oct 12, 2011 at 10:54
-
I "cracked" into their js (or looked the source of the site) and found: var UTMzdlChars="CDEFGHJKLMNPQRSTUVWXX"; function UTMzdl(latDeg) { if(-80<=latDeg&&latDeg<=84) return UTMzdlChars.charAt(Math.floor((latDeg+80)/8)); else { alert("No zdl: UTM is not valid for Lat "+latDeg); //Not normally reached return ""; } } Thank you!– MnementhCommented Oct 12, 2011 at 11:10
-
No worries, glad to have helped, I'llput it in my answer so you cna upvote me and get me past 2000 ;)– HairyCommented Oct 12, 2011 at 11:27
-
2