Postcodes freed

On 1 April the Ordnance Survey finally opened access to data relating to the location of Britain’s 1.7 million postcodes. It’s long been a gripe of many that these data were not publicly available, and various projects have attempted to collate openly available postcode data, such as Free The Postcode and http://www.npemap.org.uk/.

A while ago I wrote a PHP class for manipulating postcodes, and in particular for calculating the distance between two postcodes. I wrote it for use in a utility to help people find their nearest reputable tree surgeon by searching on their postcode, which is how it came to be named FindMyNearest. Until now I’ve relied on data gleaned from open sources, often incomplete and of unknown accuracy. I used data only down to postcode district level (eg SW1A, CV32) and stored that in a delimited text file. With the release of Code Point Open I now have the opportunity to use full postcodes of reliable provenance.

The problem was that there are about 1.7 million postcodes in Great Britain. It was fairly clear that code which used a text file for storage and slurped the entire contents into memory wasn’t going to cope well with this. So I went back to the drawing board.

I’ve rewritten FindMyNearest to provide a kind of data abstraction layer. It now supports ‘drivers’ for different types of data store. The text file option is still there, but I added the ability to use a MySQL server to store the data.

Then I came across UK Postcodes, a system based on Code Point Open put together by Pezholio. UK Postcodes provides a simple API for fetching a range of data about a postcode in XML, JSON, CSV or RDF formats. I figured it wouldn’t be too hard to add a driver that utilised this, so I did just that.

And I finally got round to working out how to use Git so I’ve just put FindMyNearest on Git-hub

Links

4 thoughts on “Postcodes freed

  1. Jamie Thompson

    It should be noted however that the Code-Point Open product omits Northern Ireland, The Channel Islands and The Isle of Man. It isn’t therefore a full UK dataset as promised but a GB one. Unfortunately this is far from ideal for most serious applications as it excludes over 2 million people 🙁

    Reply
  2. Chris Post author

    Very true. I was careful to refer to Britain or Great Britain in the post, and not to the United Kingdom.

    I have found a source of NI data at http://www.nisra.gov.uk/geography/default.asp6.htm. As far as I can make out, this can be used under the terms of the Click-use PSI licence. So I’ve put together an API for looking up UK postcodes at http://www.geopostcode.org.uk that includes the NI data. I’ve also included some limited data for the Isle of Man and the Channel Islands.

    Reply
  3. Andrew Leach

    This is great, and I expect to incorporate it into A Church Near You. It will be far less work than dealing with the [licensed!] Royal Mail data we currently get. There appears to be a typo in the API though: “Ordnance Survey Cope Point Open”

    Reply

Leave a Reply