-
Notifications
You must be signed in to change notification settings - Fork 0
/
wkt2geojson.py
executable file
·43 lines (36 loc) · 965 Bytes
/
wkt2geojson.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
#!/usr/bin/python3
import sys
import os
import json
import fiona
from shapely.wkt import dumps, loads
from shapely.geometry import mapping
print(json.dumps(mapping(loads(sys.argv[1]))))
try:
if sys.argv[2] == "-f":
if 'POINT' in sys.argv[1]:
geom_type = 'Point'
elif 'LINESTRING' in sys.argv[1]:
geom_type = 'LineString'
elif 'POLYGON' in sys.argv[1]:
geom_type = 'Polygon'
else:
print(sys.argv[1], "is not a recognised geometry type")
sys.exit(1)
schema = {
'geometry': geom_type,
'properties': {'id': 'int'}
}
with fiona.open(
os.getcwd() + "/output.geojson", "w",
driver='GeoJSON', schema=schema,
crs="EPSG:4326", encoding="UTF-8"
) as output:
output.write({
"properties": {"id": 0},
"geometry": mapping(loads(sys.argv[1]))
})
with open(os.getcwd() + "/output.geojson", "r") as r_geojson:
print(r_geojson.read())
except IndexError:
pass