-
Notifications
You must be signed in to change notification settings - Fork 51
/
geojsontosvg.py
38 lines (31 loc) · 963 Bytes
/
geojsontosvg.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
import json
height = 700
width=1200
def lolatoxy(point):
lo = point[0]
la = point[1]
x = (lo+180) * (float(width) / 360.0)
y = (180 - (la+90)) * (float(height) / 180.0)
return int(x),int(y)
def transform_to_json():
world = json.loads(open("world.json").read())
features= world["features"]
res = {}
for feature in features :
path_list = []
multipolygon= feature["geometry"]["coordinates"]
for polygon in multipolygon:
for path in polygon:
svgpath ="M %s %s " % lolatoxy(path[0])
for point in path[1:-1]:
svgpath += "L %s %s " % lolatoxy(point)
svgpath += "Z"
path_list.append(svgpath)
res[feature["properties"]["name"]]=path_list
#print res
f = open("world_svg_paths.json",'w')
f.write(json.dumps(res))
f.close()
return res
if __name__=="__main__":
transform_to_json()