Sunday, 25 March 2012

More GB postcode goodness

I have loaded the CodePoint Open data into a database some time ago. It was released as part of the OpenData from Ordnance Survey, though it is Royal Mail data originally. As part of the bundle it provides the northing and easting of the centroid of GB postcodes. I converted these OS grid references into longitude and latitude using gdaltransform and loaded them into a database. I use this to make postcode overlay tiles for use in editors or on maps.

In a recent discussion with Dan Avis I realised that I hadn't done as originally intended and created a postcode finder. When I have the data to hand it seems daft not to go the final mile, so I have. You can see it here. It uses the lovely Leaflet library to display the map and I use a small trick to only show the postcodes at high enough zoom level. Whenever the map is redisplayed I check the zoom level and hide or show the postcode tiles as required.

I have deliberately separated the attribution from the map because the text was too long for the map size I liked. In a while I will have to see what attribution changes are needed, if any, to the various maps I have created as the licence changes.

5 comments:

Tom said...

These maps are slightly fascinating, but I have a hard time interpreting the centroids and then having the confidence to add post codes to building addresses around my way:
http://oscompare.raggedred.net/?layers=B00FFT&zoom=17&lat=51.45917&lon=-0.07044

Would be useful to at least add them to individual buildings that sit right under or next to the centroid, so that people searching for a post code will always get a result at that level of accuracy. Or is that just duplicating this open data set?

Chris Hill said...

The process of adding postcode tags (usually addr:postcode=*) can be awkward. I have discussed this with people who have used the Codepoint Open data. We agree that a postcode very rarely (possibly never) includes buildings in multiple streets. Streets with more than, say, 30 houses will be split into multiple postcodes, sometimes the two sides of the road have different postcodes (I live on a street like that), sometimes the street will be broken into sections each with a separate postcode. The change of postcode is often where there is a road junction, but not always.

In general I would say have a go, add postcodes that you can, the map data can always be changed later for a the few you might get wrong. If you are not sure add a note tag to say so.

I wrote a blog about addressing (including postcodes) last year: http://chris-osm.blogspot.co.uk/2011/03/hu14.html

Chris said...

very interesting (really!).

As a trial I fed in HU14 3HZ - known to both of us to a greater or lesser extent.

What I got was not quite what I imagined from "high enough zoom level". I found that I had to zoom out a little get something that fitted for me.

Cheers

Chris Hill said...

Hi Chris,
I think I recognise that place :-)

I have not tested the page on every type of browser, but I guess it could be a little less zoomed in to be able to see the general picture. My postcode tiles are generated on-the-fly, so, to keep the DB access and processing down, I only show the postcodes for zoom level 15 and higher. At lower zooms I just paint a message saying zoom in to see postcodes. I wanted to hide that message which is why I needed to check the zoom level. In the process I just zoomed in as much as possible, to be as far away from no postcode overlay as I could, and maybe I've gone too far.

I have also considered adding a link to a full page map centred on the selected postcode. That would also have more room for detail.

It was just an experiment see how jQuery and Leaflet get along and to scratch an itch.

Anonymous said...

That's pretty good thing, people inventing post code finder to make things much easier. Thought I'd share!