This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
geojson_multi.py
74 lines (58 loc) · 1.66 KB
/
geojson_multi.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
import json
result_p = []
result_l = []
def writePoint(node):
geodata = node['geodata'][0]
#print("Point", geodata, "\n")
result_p.append({
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [geodata['lng'], geodata['lat']]
},
'properties': {
'name': getNameFromParsed(node)
}
})
def writeLineString(node):
for path in node['geodata']:
poslist = []
for geodata in path:
#print("LineString", path, "\n")
if geodata is not None and geodata['lat'] is not None and geodata['lng'] is not None:
poslist.append([geodata['lng'], geodata['lat']])
result_l.append({
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates': poslist
},
'properties': {
'name': getNameFromParsed(node)
}
})
def getNameFromParsed(node):
return node['parsed']['restriction'] + ": " + ', '.join(node['parsed']['location']['streets'])
f = open('data-parsed-2014-12-05.21-27.json')
data = json.load(f)
nodes = [node for node in data if node['geodata']]
for node in nodes:
if isinstance(node['geodata'][0], dict):
writePoint(node)
else:
writeLineString(node)
result_p = {
'type': 'FeatureCollection',
'features': result_p
}
result_l = {
'type': 'FeatureCollection',
'features': result_l
}
f = open('baustellen-lines.geo.json', 'w')
json.dump(result_l, f, indent=4)
f.close()
f = open('baustellen-points.geo.json', 'w')
json.dump(result_p, f, indent=4)
f.close()