Java library that converts latitude / longitude to MGRS coordinates and vice versa?

I am wondering which libraries exist (licensed or not), where I can find methods for converting latitude / longitude coordinates and coordinate system coordinates (mgrs). I'm obviously not looking for a converter with a long UTM, it should be mgrs. I did some search and search queries, and from what I found, lat / long for UTM often appears, but it looks like someone doesn't have a library to convert lat / long to MGRS and vice versa.

Does anyone know of any libraries or places where I can find libraries that will do such things?

Thanks, any help is appreciated.

tf.rz

+6
source share
5 answers

I know this is an old post, but I will add something else for posterity. JCoords has MGRS point conversion, but this requires a small license fee. Another source is the NASA WorldWind project (similar to Google Earth), which converted the old GeoTrans API created by NGA. This is an implementation of the MGRS conversion: MGRSCoordConverter.java

+6
source

I found a library called OpenMap in the com.bbn.openmap.proj.coords library they have a class called mgrs point. Supports a few stackoverflow questions to provide various answers. I could not find the question in this answer, but it got me the answer I was looking for: openmap! However, converting longitude latitude to mgrs points seems faulty, but the opposite works fine; and what i need.

+3
source

Another message for posterity, as my search also went up to this page. This describes and loads the Java coordinate transformation class, which includes MGRS, as well as UTM and lat / lon: http://www.ibm.com/developerworks/java/library/j-coordconvert/

The note says: "Downloading also includes MGRS methods, but the conversion from MGRS is incorrect." Perhaps this will serve as a starting point and can be fixed.

+2
source

I support @Richard Clayton's answer about the NASA WorldWind library. For those who don’t want the whole library to take a look at the minimal version of Berico Technologies, which has extracted the MGRS conversion. https://github.com/Berico-Technologies/Geo-Coordinate-Conversion-Java

0
source

I have developed the following (admittedly, javascript) functions combining bits from two primary sources and others on the Internet. I optimized them for speed without understanding!

My two main sources were: http://www.movable-type.co.uk/scripts/latlong-utm-mgrs.html http://home.hiwaay.net/~taylorc/toolbox/geography/geoutm.html

Example usage: MGRSString (51.172, -1.779) returns "30U WB 85358 69660"

function MGRSString (Lat, Long) { if (Lat < -80) return 'Too far South' ; if (Lat > 84) return 'Too far North' ; var c = 1 + Math.floor ((Long+180)/6); var e = c*6 - 183 ; var k = Lat*Math.PI/180; var l = Long*Math.PI/180; var m = e*Math.PI/180; var n = Math.cos (k); var o = 0.006739496819936062*Math.pow (n,2); var p = 40680631590769/(6356752.314*Math.sqrt(1 + o)); var q = Math.tan (k); var r = q*q; var s = (r*r*r) - Math.pow (q,6); var t = l - m; var u = 1.0 - r + o; var v = 5.0 - r + 9*o + 4.0*(o*o); var w = 5.0 - 18.0*r + (r*r) + 14.0*o - 58.0*r*o; var x = 61.0 - 58.0*r + (r*r) + 270.0*o - 330.0*r*o; var y = 61.0 - 479.0*r + 179.0*(r*r) - (r*r*r); var z = 1385.0 - 3111.0*r + 543.0*(r*r) - (r*r*r); var aa = p*n*t + (p/6.0*Math.pow (n,3)*u*Math.pow (t,3)) + (p/120.0*Math.pow (n,5)*w*Math.pow (t,5)) + (p/5040.0*Math.pow (n,7)*y*Math.pow (t,7)); var ab = 6367449.14570093*(k - (0.00251882794504*Math.sin (2*k)) + (0.00000264354112*Math.sin (4*k)) - (0.00000000345262*Math.sin (6*k)) + (0.000000000004892*Math.sin (8*k))) + (q/2.0*p*Math.pow (n,2)*Math.pow (t,2)) + (q/24.0*p*Math.pow (n,4)*v*Math.pow (t,4)) + (q/720.0*p*Math.pow (n,6)*x*Math.pow (t,6)) + (q/40320.0*p*Math.pow (n,8)*z*Math.pow (t,8)); aa = aa*0.9996 + 500000.0; ab = ab*0.9996; if (ab < 0.0) ab += 10000000.0; var ad = 'CDEFGHJKLMNPQRSTUVWXX'.charAt (Math.floor (Lat/8 + 10)); var ae = Math.floor (aa/100000); var af = ['ABCDEFGH','JKLMNPQR','STUVWXYZ'][(c-1)%3].charAt (ae-1); var ag = Math.floor (ab/100000)%20; var ah = ['ABCDEFGHJKLMNPQRSTUV','FGHJKLMNPQRSTUVABCDE'][(c-1)%2].charAt (ag); function pad (val) {if (val < 10) {val = '0000' + val} else if (val < 100) {val = '000' + val} else if (val < 1000) {val = '00' + val} else if (val < 10000) {val = '0' + val};return val}; aa = Math.floor (aa%100000); aa = pad (aa); ab = Math.floor (ab%100000); ab = pad (ab); return c + ad + ' ' + af + ah + ' ' + aa + ' ' + ab; }; 

To convert back from mgrs to lat, use the following function. The input line must have a resolution of measurement (for example, 5 digits) and a resolution to the north and have spaces as the output of the specified function.

 function LatLongFromMGRSstring (a) { var b = a.trim(); b = b.match(/\S+/g); if (b == null || b.length != 4) return [false,null,null]; var c = (b[0].length < 3) ? b[0][0] : b[0].slice(0,2); var d = (b[0].length < 3) ? b[0][1] : b[0][2]; var e = (c*6-183)*Math.PI / 180; var f = ["ABCDEFGH","JKLMNPQR","STUVWXYZ"][(c-1) % 3].indexOf(b[1][0]) + 1; var g = "CDEFGHJKLMNPQRSTUVWXX".indexOf(d); var h = ["ABCDEFGHJKLMNPQRSTUV","FGHJKLMNPQRSTUVABCDE"][(c-1) % 2].indexOf(b[1][1]); var i = [1.1,2.0,2.8,3.7,4.6,5.5,6.4,7.3,8.2,9.1,0,0.8,1.7,2.6,3.5,4.4,5.3,6.2,7.0,7.9]; var j = [0,2,2,2,4,4,6,6,8,8,0,0,0,2,2,4,4,6,6,6]; var k = i[g]; var l = Number(j[g]) + h / 10; if (l < k) l += 2; var m = f*100000.0 + Number(b[2]); var n = l*1000000 + Number(b[3]); m -= 500000.0; if (d < 'N') n -= 10000000.0; m /= 0.9996; n /= 0.9996; var o = n / 6367449.14570093; var p = o + (0.0025188266133249035*Math.sin(2.0*o)) + (0.0000037009491206268*Math.sin(4.0*o)) + (0.0000000074477705265*Math.sin(6.0*o)) + (0.0000000000170359940*Math.sin(8.0*o)); var q = Math.tan(p); var r = q*q; var s = r*r; var t = Math.cos(p); var u = 0.006739496819936062*Math.pow(t,2); var v = 40680631590769 / (6356752.314*Math.sqrt(1 + u)); var w = v; var x = 1.0 / (w*t); w *= v; var y = q / (2.0*w); w *= v; var z = 1.0 / (6.0*w*t); w *= v; var aa = q / (24.0*w); w *= v; var ab = 1.0 / (120.0*w*t); w *= v; var ac = q / (720.0*w); w *= v; var ad = 1.0 / (5040.0*w*t); w *= v; var ae = q / (40320.0*w); var af = -1.0-u; var ag = -1.0-2*ru; var ah = 5.0 + 3.0*r + 6.0*u-6.0*r*u-3.0*(u*u)-9.0*r*(u*u); var ai = 5.0 + 28.0*r + 24.0*s + 6.0*u + 8.0*r*u; var aj = -61.0-90.0*r-45.0*s-107.0*u + 162.0*r*u; var ak = -61.0-662.0*r-1320.0*s-720.0*(s*r); var al = 1385.0 + 3633.0*r + 4095.0*s + 1575*(s*r); var lat = p + y*af*(m*m) + aa*ah*Math.pow(m,4) + ac*aj*Math.pow(m,6) + ae*al*Math.pow(m,8); var lng = e + x*m + z*ag*Math.pow(m,3) + ab*ai*Math.pow(m,5) + ad*ak*Math.pow(m,7); lat = lat*180 / Math.PI; lng = lng*180 / Math.PI; return [true,lat,lng]; } 
0
source

Source: https://habr.com/ru/post/895266/


All Articles