-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoordinate.py
36 lines (26 loc) · 936 Bytes
/
coordinate.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
from pyproj import Proj, transform
import pandas as pd
#!pip install pyproj
#Check type of original coordinate data. ex: epsg:2097, epsg:5181
#Check type of target coordinate data. ex: lat/long is epsg:4326
def coordinate_transformer(data, from_type, to_type, original_x_colname, original_y_colname):
if 'csv' in data:
data = pd.read_csv(data, encoding='cp949')
elif 'xlsx' in data:
data = pd.read_excel(data)
elif 'pkl' in data:
data = pd.read_pickle(data)
proj_1 = Proj(from_type)
proj_2 = Proj(to_type)
x_list=[]
y_list=[]
for idx, row in data.iterrows():
x,y= row[original_x_colname], row[original_y_colname]
x_,y_ = transform(proj_1, proj_2, x, y)
x_list.append(x_)
y_list.append(y_)
data['lat'] = x_list
data['lng'] = y_list
print('Saving excel as data_new.pkl..')
data.to_pickle(f"data_new.pkl")
print('done!')