이동식의 latlong-gridref를 JavaScript에서 Java로 이식하는 데 문제가 있습니다. 나는 약간의 진도를 만들었지 만 지금 당황했다.이동형의 latlong-gridref 자바 스크립트를 Java로 이식하는 데 문제가 있습니다
문제 나 포팅 코드가 있어요 :
- 나는 마찬가지로
- 수 없습니다 (정말로 그것의 머리 또는 꼬리를 만들 수 없습니다)이 OsGridRef 기능을 포팅 손실 조금 있어요 ,691 : osGridToLatLong 함수에서 코드의
목적을 LatLon을 분류하는 방법을 알아낼
http://www.movable-type.co.uk/scripts/latlong-gridref.html
원래 자바 스크립트 코드 나 포트에 관리했습니다 : 363,210
는 병기 조사 그리드 참조 Y 좌표/X 좌표는 원래 자바 스크립트에 경도에게/
링크를 위도 (OSGB36) 좌표로 변환하려면 지금까지 다음과 같습니다 :
원래
/**
* Creates a OsGridRef object
*
* @constructor
* @param {Number} easting: Easting in metres from OS false origin
* @param {Number} northing: Northing in metres from OS false origin
*/
function OsGridRef(easting, northing) {
this.easting = parseInt(easting, 10);
this.northing = parseInt(northing, 10);
}
/**
* Convert Ordnance Survey grid reference easting/northing coordinate to (OSGB36) latitude/longitude
*
* @param {OsGridRef} easting/northing to be converted to latitude/longitude
* @return {LatLon} latitude/longitude (in OSGB36) of supplied grid reference
*/
OsGridRef.osGridToLatLong = function(gridref) {
var E = gridref.easting;
var N = gridref.northing;
var a = 6377563.396, b = 6356256.909; // Airy 1830 major & minor semi-axes
var F0 = 0.9996012717; // NatGrid scale factor on central meridian
var lat0 = 49*Math.PI/180, lon0 = -2*Math.PI/180; // NatGrid true origin
var N0 = -100000, E0 = 400000; // northing & easting of true origin, metres
var e2 = 1 - (b*b)/(a*a); // eccentricity squared
var n = (a-b)/(a+b), n2 = n*n, n3 = n*n*n;
var lat=lat0, M=0;
do {
lat = (N-N0-M)/(a*F0) + lat;
var Ma = (1 + n + (5/4)*n2 + (5/4)*n3) * (lat-lat0);
var Mb = (3*n + 3*n*n + (21/8)*n3) * Math.sin(lat-lat0) * Math.cos(lat+lat0);
var Mc = ((15/8)*n2 + (15/8)*n3) * Math.sin(2*(lat-lat0)) * Math.cos(2*(lat+lat0));
var Md = (35/24)*n3 * Math.sin(3*(lat-lat0)) * Math.cos(3*(lat+lat0));
M = b * F0 * (Ma - Mb + Mc - Md); // meridional arc
} while (N-N0-M >= 0.00001); // ie until < 0.01mm
var cosLat = Math.cos(lat), sinLat = Math.sin(lat);
var nu = a*F0/Math.sqrt(1-e2*sinLat*sinLat); // transverse radius of curvature
var rho = a*F0*(1-e2)/Math.pow(1-e2*sinLat*sinLat, 1.5); // meridional radius of curvature
var eta2 = nu/rho-1;
var tanLat = Math.tan(lat);
var tan2lat = tanLat*tanLat, tan4lat = tan2lat*tan2lat, tan6lat = tan4lat*tan2lat;
var secLat = 1/cosLat;
var nu3 = nu*nu*nu, nu5 = nu3*nu*nu, nu7 = nu5*nu*nu;
var VII = tanLat/(2*rho*nu);
var VIII = tanLat/(24*rho*nu3)*(5+3*tan2lat+eta2-9*tan2lat*eta2);
var IX = tanLat/(720*rho*nu5)*(61+90*tan2lat+45*tan4lat);
var X = secLat/nu;
var XI = secLat/(6*nu3)*(nu/rho+2*tan2lat);
var XII = secLat/(120*nu5)*(5+28*tan2lat+24*tan4lat);
var XIIA = secLat/(5040*nu7)*(61+662*tan2lat+1320*tan4lat+720*tan6lat);
var dE = (E-E0), dE2 = dE*dE, dE3 = dE2*dE, dE4 = dE2*dE2, dE5 = dE3*dE2, dE6 = dE4*dE2, dE7 = dE5*dE2;
lat = lat - VII*dE2 + VIII*dE4 - IX*dE6;
var lon = lon0 + X*dE - XI*dE3 + XII*dE5 - XIIA*dE7;
return new LatLon(lat.toDeg(), lon.toDeg());
}
당신이 자바 스크립트 어떤 경험이 있습니까 포트
LatLon osGridToLatLong(OsGridRef osGridRef) {
int E = osGridRef.easting;
int N = osGridRef.northing;
double a = 6377563.396, b = 6356256.910; // Airy 1830 major & minor semi-axes
double F0 = 0.9996012717; // NatGrid scale factor on central meridian
double lat0 = 49*Math.PI/180, lon0 = -2*Math.PI/180; // NatGrid true origin
double N0 = -100000, E0 = 400000; // northing & easting of true origin, metres
double e2 = 1 - (b*b)/(a*a); // eccentricity squared
double n = (a-b)/(a+b), n2 = n*n, n3 = n*n*n;
double lat=lat0, M=0;
int count = 0;
do {
count++;
lat = (N-N0-M)/(a*F0) + lat;
double Ma = (1 + n + (5.0/4)*n2 + (5.0/4)*n3) * (lat-lat0);
double Mb = (3*n + 3*n*n + (21/8)*n3) * Math.sin(lat-lat0) * Math.cos(lat+lat0);
double Mc = ((15/8)*n2 + (15/8)*n3) * Math.sin(2*(lat-lat0)) * Math.cos(2*(lat+lat0));
double Md = (35/24)*n3 * Math.sin(3*(lat-lat0)) * Math.cos(3*(lat+lat0));
M = b * F0 * (Ma - Mb + Mc - Md); // meridional arc
} while (N-N0-M >= 0.00001); // ie until < 0.01mm
double cosLat = Math.cos(lat), sinLat = Math.sin(lat);
double nu = a*F0/Math.sqrt(1-e2*sinLat*sinLat); // transverse radius of curvature
double rho = a*F0*(1-e2)/Math.pow(1-e2*sinLat*sinLat, 1.5); // meridional radius of curvature
double eta2 = nu/rho-1;
double tanLat = Math.tan(lat);
double tan2lat = tanLat*tanLat, tan4lat = tan2lat*tan2lat, tan6lat = tan4lat*tan2lat;
double secLat = 1/cosLat;
double nu3 = nu*nu*nu, nu5 = nu3*nu*nu, nu7 = nu5*nu*nu;
double VII = tanLat/(2*rho*nu);
double VIII = tanLat/(24*rho*nu3)*(5+3*tan2lat+eta2-9*tan2lat*eta2);
double IX = tanLat/(720*rho*nu5)*(61+90*tan2lat+45*tan4lat);
double X = secLat/nu;
double XI = secLat/(6*nu3)*(nu/rho+2*tan2lat);
double XII = secLat/(120*nu5)*(5+28*tan2lat+24*tan4lat);
double XIIA = secLat/(5040*nu7)*(61+662*tan2lat+1320*tan4lat+720*tan6lat);
double dE = (E-E0), dE2 = dE*dE, dE3 = dE2*dE, dE4 = dE2*dE2, dE5 = dE3*dE2, dE6 = dE4*dE2, dE7 = dE5*dE2;
lat = lat - VII*dE2 + VIII*dE4 - IX*dE6;
double lon = lon0 + X*dE - XI*dE3 + XII*dE5 - XIIA*dE7;
return new LatLon(lat.toDeg(), lon.toDeg());
}