Opening up geographic data is beginning to bear fruit. MySociety’s Matthew Somerville has just unveiled MaPit, ‘our database and web service that maps postcodes and points to current or past administrative area information and polygons for all the United Kingdom.’ What that means in practice is, postcode lookups and boundary data are now just a URL away.
(Quick update: actually, not for all the United Kingdom as it turns out – the following method doesn’t work for N Ireland. See Matthew’s comment below.)
Here’s a quick example, as much for my own future reference as anyone else’s. Let’s say you wanted to generate a map of a given MP’s constituency – say Lynne Featherstone in Hornsey & Wood Green:
- You need to find the appropriate reference number for the constituency: either by browsing the list of all constituencies, or searching for places whose names begin with Hornsey. Note – these will produce nasty-looking data files, rather than pretty HTML lists. Hunt through the code, and you’ll find:
“65883”: {“codes”: {“unit_id”: “25044”}, “name”: “Hornsey and Wood Green”, “country”: “E”, “type_name”: “UK Parliament constituency”, “parent_area”: null, “generation_high”: 13, “generation_low”: 13, “country_name”: “England”, “type”: “WMC”, “id”: 65883}
- The ‘id’ is the number you need – in this case, 65883. The MySociety API now lets you call the geometry of that area, in – among others – Google Earth’s KML format, using the following URL. (Don’t worry about the ‘4326’ here: it’s a reference to the coordinate system being used, and won’t change in this context.)
http://mapit.mysociety.org/area/4326/65883.kml
- Conveniently, Google Maps lets you enter a KML file’s URL as a search query, and it will draw it on a map. Even more conveniently, if you add ‘output=embed’ as a search parameter, it strips away everything but the map itself. So here’s an embedded map of Lynne’s constituency, pulled into an <iframe>. Look at the source code, to see how easy it is.
Boundary data generated by MaPit.mysociety.org which contains Ordnance Survey data ยฉ Crown copyright and database right 2010; Royal Mail data ยฉ Royal Mail copyright and database right 2010 (Code-Point Open); National Statistics data ยฉ Crown copyright and database right 2010 (NSPD Open).
And thankfully, it bears a close resemblance to this map on Lynne’s own website, which took me considerably longer to churn out.