Accurate Postcode data for the UK and Northern Ireland

by on Jun.06, 2011, under Knowledge Base, Technology

Getting accurate postcode data for use in my programs has proved to be an interesting technical challenge, despite the availability of free services such as those from Google.

I needed a UK postcode to Latitude/Longitude conversion tool that would work offline, which made the Google API’s completely useless.

A freely available dataset was made available from the Ordnance Survey under the moniker of “Code-point open”, however this is missing some data (notably Northern Ireland) so can’t really be called complete, and additionally it does not provide locations in Latitude/Longitude, but instead it uses Ordnance Survey Grid references.

If you need to do this, then hopefully the tools here will be of some help.

First we need to grab the Ordnance Survey Code-point open dataset. They don’t provide a straight link, so you will need to register to actually get access to the data. Once downloaded and extracted you will have a folder full of CSV files.

Secondly we need to convert the grid references to more useable LatLong values. Chris Veness has written some Javascript to do just that – as well as writing some incredibly informative articles about how this stuff actually works (there’s some horrible maths involved!). I spent a couple of evenings converting his scripts to Python and wrote a little data extract utility which put all the data into a SQLite3 database.

Another couple of hours to write a set of wrapper functions around the database and include the validation rules from the UK government data schema and hey presto! We have a usable postcode_utils module.

This just leaves Northern Ireland…

It turns out that the Northern Ireland Statistics and Research Agency (NISRA) have some GIS data available in ESRI ShapeFile format. There is a useful Python library to work with ESRI Shapefiles and it took a matter of minutes to extract the coordinates from the NISRA data, that provides postcodes in… bah! another Grid System, but this time it’s the Irish Grid!

Some more hunting online to get the right values for the grid transformations and the Geoid dimensions used for each grid system and a bit of tinkering with Chris Veness’ code and we are done! Here is a Sqlite3 database containing all the postcodes in Great Britain and Northern Ireland with accurate Latitude and Longitudes (more accurate than some Web Services I could mention) and some Python to use with it. Also, this information is all freely available and free for use commercially and non-commercial use (provided you give attribution as mentioned on the various sites linked to above).

If you find this useful, please let me know by using the comments feature. Also, if anybody has a source of data for the Channel Islands or the Isle of Man I would be very please to find them!

:, , , ,

3 Comments for this entry

  • JSamson

    Thank you! I requested the “Code-Point Open” data today but was disappointed they didn’t include latitude / longitude values. This has saved me a massive amount of time / hassle.

    Is this supposed to contain every postcode in the UK? I tried a few and it seems very accurate.

  • Mike


    The database contains every valid postcode in England, Scotland, Wales and Northern Ireland.

    To be absolutely complete, I need to get the Channel Islands and Isle of Man postcodes too but I haven’t managed to find a freely available source of data for those yet.

    Glad it is of use to you!

  • Dean

    I have been looking at correctly naming towns to postcode districts and found I believe this site has channel island data but im afraid its not free. If anyone has this data for free I would really like a copy of it.

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!