-
Notifications
You must be signed in to change notification settings - Fork 2
/
2_offset_WGS84.py
43 lines (40 loc) · 1.03 KB
/
2_offset_WGS84.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#coding:utf-8
import math
import numpy as np
def convert(offset_x,offset_y,x,y,pre_X,pre_Y,distance):
X = x - offset_x
Y = y - offset_y
#print X,Y,distance
dif = math.sqrt((X-pre_X)**2 + (Y-pre_Y)**2)
distance += dif
#print X,Y,int(distance)
return X,Y,distance
#filename = raw_input('please enter the input file name\n--->')
#filename2 = raw_input('please enter the output file name\n--->')
a = open('data/xy_WGS84.csv','r')
b = open('data/xy_WGS84_offseted.csv','w')
b.write('marker,x_offseted[m],y_offseted[m],distance[m]\n')
num = 0
offset_x = 0.0
offset_y = 0.0
pre_X = 0.0
pre_Y = 0.0
distance = 0.0
for i in a:
if num >= 1:
LINE = i.rstrip().replace('"','').split(',')
marker = LINE[0]
x = float(LINE[1])
y = float(LINE[2])
X,Y = 0.0, 0.0
if num==1:
offset_x = x
offset_y = y
else:
X, Y, distance = convert(offset_x,offset_y,x,y,pre_X,pre_Y,distance)
print marker,X,Y,int(distance)
b.write(marker+','+str(X)+','+str(Y)+','+str(int(distance))+'\n')
pre_X, pre_Y = X, Y
num+=1
a.close()
b.close()