作者StubbornLin (Victor)
看板Geography
標題[問題] 為什麼lat/lon轉TWD97的lon會有十幾公尺的誤差
時間Thu Aug 13 17:09:06 2009
我自己照著
http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.htm
寫的公式寫了一個從lat/lon轉TWD97的python程式
from math import tan, sin, cos, radians
class LatLonToTWD97(object):
"""This object provide method for converting lat/lon coordinate to TWD97
coordinate
the formula reference to
http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.htm (there is lots of
typo)
http://www.offshorediver.com/software/utm/Converting UTM to Latitude and
Longitude.doc
Parameters reference to
http://rskl.geog.ntu.edu.tw/team/gis/doc/ArcGIS/WGS84%20and%20TM2.htm
http://blog.minstrel.idv.tw/2004/06/taiwan-datum-parameter.html
"""
def __init__(self,
):
# Equatorial radius
self.a = 6378137.0
# Polar radius
self.b = 6356752.314245
# central meridian of zone
self.long0 = radians(121)
# scale along long0
self.k0 = 0.9999
# eccentricity of the earth's elliptical cross-section
self.e = (1-self.b**2/self.a**2)**0.5
# delta x in meter
self.dx = 250000
def convert(self, lat, lon):
"""Convert lat lon to twd97
"""
a = self.a
b = self.b
long0 = self.long0
k0 = self.k0
e = self.e
dx = self.dx
e2 = e**2/(1-e**2)
n = (a-b)/(a+b)
nu = a/(1-(e**2)*(sin(lat)**2))**0.5
p = lon-long0
A = a*(1 - n + (5/4.0)*(n**2 - n**3) + (81/64.0)*(n**4 - n**5))
B = (3*a*n/2.0)*(1 - n + (7/8.0)*(n**2 - n**3) + (55/64.0)*(n**4 -
n**5))
C = (15*a*(n**2)/16.0)*(1 - n + (3/4.0)*(n**2 - n**3))
D = (35*a*(n**3)/48.0)*(1 - n + (11/16.0)*(n**2 - n**3))
E = (315*a*(n**4)/51.0)*(1 - n)
S = A*lat - B*sin(2*lat) + C*sin(4*lat) - D*sin(6*lat) + E*sin(8*lat)
K1 = S*k0
K2 = k0**nu*sin(2*lat)/4.0
K3 = (k0*nu*sin(lat)*(cos(lat)**3)/24.0) * \
(5 - tan(lat)**2 + 9*e2*(cos(lat)**2) + 4*(e2**2)*(cos(lat)**4))
y = K1 + K2*(p**2) + K3*(p**4)
K4 = k0*nu*cos(lat)
K5 = (k0*nu*(cos(lat)**3)/6.0) * \
(1 - tan(lat)**2 + e2*(cos(lat)**2))
x = K4*p + K5*(p**3) + self.dx
return x, y
公式本身我檢查好幾次了,應該是沒有打錯了,包括網頁裡打錯的部份
像51被誤打成512,然後an被打成tan也都有修正
可是不知道為什麼,算出來的結果lat誤差都在公尺之內,而lon總是有幾十公尺的誤差
像是我用這裡面的三角點資料來做測試
http://wiki.osgeo.org/index.php?title=Taiwan_datums/Test_points&uselang=zh-tw
挑個七星山當輸入的話
25.17069939, 121.5534442
我的程式算出來的結果是
305787.782217, 2784684.75762
而裡面寫的資料是
305787.783, 2784799.355
可以發現lat幾乎都很精準
而lon卻差了-114.59738公尺
不只是那三角點的資料,我也有找其它轉換程式去算
結果也都是lat誤差在公尺以下,而long誤差在十幾公尺到上百公尺
請問我可能是哪裡弄錯了? 參數弄錯? 還是?
為什麼會有這long誤差這麼大的問題?
因為這要拿來當做導航用的,long誤差百公尺可以從路面跑進河裡或任何地方 囧
以上,謝謝
--
哇咧咧 創意投票系統
http://walele.com
易記學 程式設計教學
http://ez2learn.com/
易記學 程式設計討論區
http://forum.ez2learn.com
VICTOR's 個人Blog
http://blog.ez2learn.com/
財報分析王
http://victorlin.serveftp.org/stock/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.165.225.76
1F:→ nehex:E = (315*a*(n**4)/512.0)*(1 - n) 08/13 18:05
2F:→ nehex: ^^^ 08/13 18:06
3F:→ nehex:另 geog.ntu 那個網頁也不建議使用 @@ 08/13 18:13
4F:→ nehex:噢噢 doc 的 反而又錯了 :P 08/13 18:17
5F:→ nehex:llh tm 互轉誤差是可以無視的... @@ 08/13 18:23
6F:→ nehex:= = 不管是 512 還是 51 都不影響 08/13 18:50