Tag Archives: code point

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