-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3-get_wards.py
More file actions
28 lines (20 loc) · 759 Bytes
/
Copy path3-get_wards.py
File metadata and controls
28 lines (20 loc) · 759 Bytes
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
import json
import requests
WARD_ID = '2529'
wards_url = 'http://mapit.mysociety.org/area/{key}/children'
ward_geometry_url = 'http://mapit.mysociety.org/area/{key}.geojson'
all_wards = {
"type": "FeatureCollection",
"features": []
}
wards = json.loads(requests.get(wards_url.format(key=WARD_ID)).text)
for key, ward_properties in wards.iteritems():
if ward_properties['type'] == 'MTW': #Metropolitan district ward
ward_geometry = json.loads(requests.get(ward_geometry_url.format(key=key)).text)
all_wards["features"].append({
"type": "Feature",
"geometry": ward_geometry,
"properties": ward_properties
})
with open('wards.geojson', 'w') as f:
f.write(json.dumps(all_wards))