UK Postcode database with lat & long

As we all know the full postcode database with all latitude and longitude information is Copyright to Royal Mail. This is annoying. I know there are loads of databases out there which claim to be the full dataset and there are loads of API’s which will geocode UK postcodes etc. In the past we have used an awesome service called PostcodeAnywhere which does a great job of address lookup and validation… but it’s a paid service… obviously they have to make money somehow! I have also played with Google API etc. I also think that someone released a dataset on Wikileaks but if I remember rightly this was partial postcodes (only contains the first part of the postcode e.g. TS19).

I was chatting to Alex Akass on skype the other day and he pointed me to the Ordnance Survey website who have just released a full set of UK postcodes in a database as recent as February 2012! The service, called Code-Point Open (ordnancesurvey.co.uk) contains 2,993,351 rows. This data also looks to be available on the new data.gov.org beta site under the same name Code-Point Open (data.gov.uk).

The data comes in CSV files to split the data up. I created a quick PHP script that looped through these files and put all the postcodes into one database table. All looks good.

This got me thinking. The database comes with ‘Postcode’, ‘Eastings’ & ‘Northings’ columns. There must be something you can run Eastings and Northings through to get the latitude and longitude. I did a quick Google and found a post by a guy called samjudson on this forum.

I searched for my postcode in the database and then ran the Northings and Eastings through this function to get the latitude and longitude. I used itouchmap.com to load this data on the map and compared it with the pointer that got shown on the map when I inputted my postcodes directly. They were very close, close enough to be useful I think.

So what I was thinking, was I could add the conversion function to my php script and whilst I am looping through the csv files I could also add the latitude and longitude and I will end up with a current table with full UK postcode, Eastings, Northings, Latitude & Longitude.

Would welcome thoughts…

7 thoughts on “UK Postcode database with lat & long

  1. Simon Hewison says:

    Sadly, the OS codepoint open dataset is not UK wide, because for some historical quirk, there is a different organisation that does the official mapping of Northern Ireland (OSNI), and they haven’t released their equivalent datasets yet.

Leave a Reply

Your email address will not be published. Required fields are marked *