樹心幽徑

« C GPX Reader Project STEP1: 20170423將WGS84經緯度座標轉TWD97(TWD67)二度分帶座標 | Main | 20170502ubuntu network setup »

20170424將WGS84台灣經緯度座標轉TWD97二度分帶座標Java Script
2017/04/24,16:31
<title>WGS84台灣經緯度座標轉TWD97二度分帶座標</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<body bgcolor=lightgreen>

<script language="JavaScript">

function lonlat2twd97twd67(lon,lat)
{
var x97,y97;
var a,b,long0,k0,dx;
var e,e2,n,nu,p;
var A,B,C,D,E,S;
var K1,K2,K3;
var K4,K5;
        a = 6378137.0;
        b = 6356752.314245;
        long0 = 121.0*Math.PI/180.0;
        k0 = 0.9999;
        dx = 250000;


        e = Math.pow(1-(b*b)/(a*a),0.5);
        e2 = Math.pow(e,2)/(1-Math.pow(e,2));
        n = (a-b)/(a+b);
        nu = a/Math.pow(1-Math.pow(e,2)*Math.pow(Math.sin(lat),2),0.5);
        p = lon-long0;
        A = a*(1 - n + (5/4.0)*(Math.pow(n,2) - Math.pow(n,3)) + (81/64.0)*(Math.pow(n,4)  - Math.pow(n,5)));
        B = (3*a*n/2.0)*(1 - n + (7/8.0)*(Math.pow(n,2) - Math.pow(n,3)) + (55/64.0)*(Math.pow(n,4) - Math.pow(n,5)));
        C = (15*a*Math.pow(n,2)/16.0)*(1 - n + (3/4.0)*(Math.pow(n,2) - Math.pow(n,3)));
        D = (35*a*Math.pow(n,3)/48.0)*(1 - n + (11/16.0)*(Math.pow(n,2) - Math.pow(n,3)));
        E = (315*a*Math.pow(n,4)/51.0)*(1 - n);
        S = A*lat - B*Math.sin(2*lat) + C*Math.sin(4*lat) - D*Math.sin(6*lat) + E*Math.sin(8*lat);
        K1 = S*k0;
        K2 = k0*nu*Math.sin(2*lat)/4.0;
        K3 = (k0*nu*Math.sin(lat)*Math.pow(Math.cos(lat),3)/24.0) * (5.0 - Math.pow(Math.tan(lat),2) + 9.0*e2*Math.pow(Math.cos(lat),2) + 4.0*Math.pow(e2,2)*Math.pow(Math.cos(lat),4));
        y97 = K1 + K2*Math.pow(p,2) + K3*Math.pow(p,4);

        K4 = k0*nu*Math.cos(lat);
        K5 = (k0*nu*Math.pow(Math.cos(lat),3)/6.0) * (1 - Math.pow(Math.tan(lat),2) + e2*Math.pow(Math.cos(lat),2));
        x97 = K4*p + K5*Math.pow(p,3) + dx;

        document.write("TWD97 (" + x97 +"," + y97 + ")<br>" );

	x67=x97-807.8-0.00001549*x97-0.000006521*y97;
        y67=y97+248.6-0.00001549*y97-0.000006521*x97;

        document.write("TWD67 (" + x67 +"," + y67 + ")<br>" );


}


function change_wgs84()
{
	var lon,lat,londeg,latdeg;
	var query=document.frm.wgs84.value;
	var res = query.split(",");

        document.write("(" +res[0]+"," +res[1]+")<br>");
	londeg=parseFloat(res[0]);
	latdeg=parseFloat(res[1]);
	lon=londeg*Math.PI/180.0; 
	lat=latdeg*Math.PI/180.0;
	lonlat2twd97twd67(lon,lat)

}

</script>
<form name='frm' METHOD=POST ACTION='' onsubmit='return validation();'>
<div align="center">

將WGS84經緯度座標轉TWD97,TWD67<br>
台灣虎子山經緯度WGS84=120.982025,23.973875 <br>
其二度分帶座標T<br>
TWD97=248170.787,2652129.936  <br>
TWD67=247341.925, 2652335.811<br>
輸入要轉換WGS84經緯度座標(lon,lat):<input type=text name=wgs84 size=40 value="120.982025,23.973875"  onchange="change_wgs84()"> <br>

</form>
<br>
<script language="JavaScript">
var lon,lat,londeg,latdeg,x,y;

londeg=120.982025;
latdeg=23.973875;

document.write("WGS84台灣經緯度座標: (" + londeg +"," + latdeg + ")<br>" );

lon=londeg*Math.PI/180.0; 
lat=latdeg*Math.PI/180.0;


lonlat2twd97twd67(lon,lat)


document.write("本頁最後更新日期:"+document.lastModified+"<br>");

</script>
</div>
</body>

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType