Datum transformation in Python

23 08 2009

ได้โค้ดดีๆ มา ก็เอาไว้แปลงพื้นหลักฐาน เขียนโดยภาษาไพธอน

โดยคุณ Tyler Mitchell คนเขียนหนังสือ

Web Mapping Illustrated: Using Open Source GIS Toolkits

>>from numpy import *
>>from scipy import *
>>L = io.readarray(str(‘locale’))
>>G = io.readarray(str(‘globale’))
>>L

array([[ 496.4 , -14853.55],
[ -405.58, -15197.24],
[ 602.12, -15273.71],
[ 643.14, -15141.68]])

>>G

array([[ 2561715.65, 4444638.81],
[ 2560815.52, 4444289.81],
[ 2561823.58, 4444219.83],
[ 2561863.75, 4444351.03]])

>>A = zeros((2*L.shape[0],4),float)
>>A

array([[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]])

>>A[ ::2, 0] = 1.0
>>A[1::2, 1] = 1.0
>>A[ ::2, 2] = L[:,0]
>>A[1::2, 2] = L[:,1]
>>A[ ::2, 3] = L[:,1]
>>A[1::2, 3] = -L[:,0]
>>A

array([[ 1.00000000e+00, 0.00000000e+00, 4.96400000e+02,
-1.48535500e+04],
[ 0.00000000e+00, 1.00000000e+00, -1.48535500e+04,
-4.96400000e+02],
[ 1.00000000e+00, 0.00000000e+00, -4.05580000e+02,
-1.51972400e+04],
[ 0.00000000e+00, 1.00000000e+00, -1.51972400e+04,
4.05580000e+02],
[ 1.00000000e+00, 0.00000000e+00, 6.02120000e+02,
-1.52737100e+04],
[ 0.00000000e+00, 1.00000000e+00, -1.52737100e+04,
-6.02120000e+02],
[ 1.00000000e+00, 0.00000000e+00, 6.43140000e+02,
-1.51416800e+04],
[ 0.00000000e+00, 1.00000000e+00, -1.51416800e+04,
-6.43140000e+02]])

>>Y = zeros((2*G.shape[0],1),float)

array([[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.]])

>>Y[ ::2, 0] = G[:,0]
>>Y[1::2, 0] = G[:,1]
>>Y

array([[ 2561715.65],
[ 4444638.81],
[ 2560815.52],
[ 4444289.81],
[ 2561823.58],
[ 4444219.83],
[ 2561863.75],
[ 4444351.03]])

>>N = dot(A.T.conj(), A)
>>T = dot(A.T.conj(), Y)
>>C = dot(linalg.inv(N), T)
>>C

array([[ 2.56113298e+06],
[ 4.45948730e+06],
[ 9.99856124e-01],
[ -5.80009571e-03]])

>>E0 = C[0]
>>N0 = C[1]
>>a = C[2]
>>b = C[3]
>>x = E0 + L[0,0] * a + L[0,1] * b
>>y = N0 + L[0,1] * a – L[0,0] * b
>>print x,y

[ 2561715.45624184] [ 4444638.76898143]

อ้างอิงจาก Spatialguru.com


Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: