Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (20 sloc)
759 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |