Last active
August 29, 2015 14:25
-
-
Save Poshan/734b2aa4ca3e64e33dea to your computer and use it in GitHub Desktop.
code to convert the (Easting, Northing) MUTM data (datum : Everest-1830) to Latitude Longitude in datum WGS-84
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//test data | |
// 632750,3024751,1230 and zone 88 (3 degree UTM zone) | |
data = { | |
"N" : 3038250, | |
"E" : 617000, | |
"ht": 1230, | |
"zone": 88 | |
}; | |
//parameters of Everest-1830 | |
everestParams = { | |
"e" : 0.08147298125166744, | |
"f" : 0.0033244493186534527, | |
"e2": 0.0066378466740345775,//square of the eccentricity | |
// "e2": 0.00667054, | |
"a": 6377276.345,//semi major axis of Everest-1830 | |
// "a": 6377563.396, | |
"if": 300.8016980102568, | |
"fE": 500000, | |
"phi0": 0,//latitude of the natural origin | |
// "fE": 400000, | |
"fN": 0, | |
"k0": 0.9999, | |
// "k0": 0.9996012717, | |
"M0": 0 //for latitude of origin 0 | |
}; | |
//parameters of wgs-84 | |
wgsParams = { | |
"a" : 6378137.0, | |
"e" : 0.08181919092890624, | |
"e2": 0.006694380004260827, | |
"f" : 0.0033528106718309896 | |
}; | |
//transformation parameters | |
transformParams = { | |
"dx" : 282, | |
"dy" : 726, | |
"dz" : 254 | |
}; | |
//calculations used in the formula | |
function esquareby4(){ | |
return (everestParams["e2"]/4) | |
}; | |
function threee4by64(){ | |
return (3*(everestParams["e2"])*(everestParams["e2"])/64); | |
}; | |
function fivee6by256(){ | |
return (5*(Math.pow(everestParams["e2"], 3)/256)); | |
}; | |
function capitalM1(){ | |
return (everestParams["M0"] + ((data["N"] - everestParams["fN"])/everestParams["k0"])); | |
}; | |
//mue1 | |
function mue1(){ | |
var numerator = capitalM1(); | |
var denom = everestParams["a"] * (1- esquareby4() - threee4by64() - fivee6by256()); | |
// console.log(numerator/denom); | |
return (numerator/denom); | |
}; | |
//calculations | |
function rootoneminuse2(){ | |
return Math.pow((1-everestParams["e2"]), 0.5); | |
}; | |
function e1(){ | |
return ((1 - rootoneminuse2())/(1 + rootoneminuse2())); | |
}; | |
function threee1by2(){ | |
return (3* e1()/2); | |
}; | |
function twenty7e1cubeby32(){ | |
return (27* Math.pow(e1(), 3)/32); | |
}; | |
function sinmue1(x){ | |
var xmue1 = x * mue1(); | |
return Math.sin(xmue1); | |
}; | |
function twenty1e1squareby16(){ | |
return (21* Math.pow(e1(), 2)/16); | |
}; | |
function fifty5e1power4by32(){ | |
return (55 * Math.pow(e1(), 4)/32); | |
}; | |
function hundred51e1power3by96(){ | |
return (151 * Math.pow(e1(),3)/96); | |
}; | |
function thousand97e1power4by512(){ | |
return (1097 * Math.pow(e1(),4)/512); | |
}; | |
//phi1 | |
function phi1(){ | |
return (mue1() + ((threee1by2() - twenty7e1cubeby32()) * sinmue1(2)) + ((twenty1e1squareby16() - fifty5e1power4by32()) * sinmue1(4)) + (hundred51e1power3by96() * sinmue1(6)) + (thousand97e1power4by512() * sinmue1(8))); | |
}; | |
//v1 | |
function v1(){ | |
var numerator = everestParams["a"]; | |
var denominator = Math.pow((1 - everestParams["e2"] * Math.pow (Math.sin(phi1()), 2)), 0.5); | |
return(numerator/denominator); | |
}; | |
//row1 | |
function row1(){ | |
return(v1()*v1()*v1()*(1 - everestParams["e2"])/(everestParams["a"]*everestParams["a"])); | |
}; | |
//T1 | |
function T1(){ | |
return (Math.pow(Math.tan(phi1()), 2)); | |
}; | |
//e'2 | |
function edash2(){ | |
var numerator = everestParams["e2"]; | |
var denominator = (1- everestParams["e2"]); | |
return (numerator/denominator); | |
}; | |
//c1 | |
function C1(){ | |
return (edash2() * (Math.pow(Math.cos(phi1())),2)); | |
}; | |
//D1 | |
function D(){ | |
return ((data["E"] - everestParams["fE"])/(v1() * everestParams["k0"])); | |
}; | |
//calculations | |
function Dsquare(){ | |
return Math.pow(D(),2); | |
}; | |
function C1square(){ | |
return (Math.pow(C1(),2)); | |
}; | |
//the latitude | |
function phi(){ | |
// debugger; | |
var firstTerm = phi1()*180/Math.PI; | |
var secondTermpart1 = v1() * Math.tan(phi1()) / row1(); | |
var secondTermpart2_1 = Dsquare()/2; | |
var secondTermpart2_2 = (5 + 3 * T1() + 10 * C1() - 4 * C1square() - 9 * edash2()) * (Dsquare()/24); | |
var secondTermpart2_3 = (61 + 90 * T1() + 298 * C1() + 45 * T1() * T1() - 252 * edash2() - 3 * C1square()) * (Math.pow(D(), 6)/720); | |
var secondTermpart2 = secondTermpart2_1 - secondTermpart2_2 + secondTermpart2_3; | |
var secondTerm = secondTermpart1 * secondTermpart2; | |
// debugger; | |
return (firstTerm - secondTerm); | |
}; | |
//central meridian | |
function lamda0() { | |
if (data["zone"] == 87) { | |
return 81; | |
} | |
else if (data["zone"] == 88) { | |
return 84; | |
} | |
else { | |
return 87; | |
} | |
}; | |
//FOrmula of D for ZOned UTM | |
function DLamda(){ | |
// return D(); | |
return ((data["E"] - everestParams["fE"] - (88 * Math.pow(10,4)))/(v1() * everestParams["k0"])); | |
}; | |
//longitude | |
function lamda(){ | |
var firstTerm = lamda0(); | |
var secondTerm1 = DLamda(); | |
var secondTermpart2 = (1 + 2 * T1() + C1()) * (Math.pow(DLamda(), 3)/6); | |
var secondTermpart3 = (5 - 2 * C1() + 28 * T1() - 3 * C1() * C1() + 8 * edash2() + 24 * T1() * T1()) * (Math.pow(DLamda(), 5)/120); | |
var secondTermDenom = Math.cos(phi1()); | |
var secondTermNum = secondTerm1 - secondTermpart2 + secondTermpart3; | |
var secondTerm = secondTermNum/secondTermDenom; | |
return (firstTerm + secondTerm); | |
}; | |
//transformation using molodensky 3 parameters | |
//transformation OF Everest Lat/lng to WGS lat/lng | |
function sinLat(){ | |
return Math.sin(phi()); | |
}; | |
function cosLat(){ | |
return Math.cos(phi()); | |
}; | |
function sinLng(){ | |
return Math.sin(lamda()); | |
} | |
function cosLng(){ | |
return Math.cos(lamda()); | |
}; | |
function ssqlat(){ | |
return Math.pow(sinLat(),2); | |
}; | |
function adb(){ | |
return 1/(1 - everestParams["f"]); | |
}; | |
function rn(){ | |
return (everestParams["a"]/(Math.pow((1-everestParams["e2"] * ssqlat()),0.5))); | |
}; | |
function rm(){ | |
return (everestParams["a"] * (1 - everestParams["e2"])/Math.pow((1 - everestParams["e2"]*ssqlat()),2)); | |
}; | |
function da(){ | |
return (wgsParams["a"] - everestParams["a"]); | |
}; | |
function df(){ | |
return (wgsParams["f"] - everestParams["f"]); | |
}; | |
function dlat(){ | |
// debugger; | |
return ((((((-transformParams["dx"] * sinLat() * cosLng() - transformParams["dy"] * sinLat() * sinLng()) + transformParams["dz"] * cosLat()) + (da() * ((rn() * everestParams["e2"] * sinLat() * cosLat()) / everestParams["a"]))) + (df() * (rm() * adb() + rn() / adb()) * sinLat() * cosLat())))/ (rm() + data["ht"])); | |
}; | |
function dlng(){ | |
return(-transformParams["dx"] * sinLng() + transformParams["dy"] * cosLng()) / ((rn() + data["ht"]) * cosLat()); | |
}; | |
var dlng1 = dlng(); //change in longitude from transformation | |
var dlat1 = dlat(); //change in latitude from transformation | |
var dlat1_dg = dlat1 * 180/ Math.PI; | |
var dlng1_dg = dlng1 * 180/ Math.PI; | |
var phi2 = phi(); //Everest Lat | |
var lamda1 = lamda(); //Everest Long | |
var new_lat = phi2 + dlat1_dg; // | |
var new_lng = lamda1 + dlng1_dg; | |
console.log('WGS-lat'); | |
console.log(new_lat); | |
console.log('WGS lng'); | |
console.log(new_lng); | |
console.log('Everest-1830 lat'); | |
console.log(phi2); | |
console.log('Everest-1830 lng'); | |
console.log(lamda1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment