forked from ayang861/parcelization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boundary_wkt.py
46 lines (36 loc) · 1.24 KB
/
boundary_wkt.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
44
45
46
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 1 19:47:05 2018
@author: Annie
"""
file_name = "lagos_test.csv"
import pandas as pd
import_df = pd.read_csv(file_name)
columnhead = ""
if 'verification/A0_Boundary' in import_df:
columnhead = 'verification/A0_Boundary'
elif 'C2a. Settlement Boundary' in import_df:
columnhead = 'C2a. Settlement Boundary'
elif 'section_C/C2_Boundary' in import_df:
columnhead = 'section_C/C2_Boundary'
export_df = import_df[['device_id',columnhead]].copy()
export_df[columnhead] = export_df[columnhead].fillna("no bounds")
export_df
def switchcoords(text):
text= text.split(";")
if len(text) < 3: #invalid number of coords
return text
coords = [] # list of x y coords
for i in text:
line = i.split()
coord = line[1] +" " + line[0]
coords.append(coord)
fcoord = coords[0]
lcoord = coords.append(fcoord)
polygon = "POLYGON((" + ",".join(coords) + "))" #polygon string
return polygon
export_df[columnhead] = export_df[columnhead].apply(switchcoords)
#check output dataframe contains desired fields
print(export_df['device_id'])
print(export_df[columnhead])
export_df.to_csv('lagos_test_wkt.csv')