A gazetter combining the three OS OpenData gazetteers, CodePoint Open, 1:50k Gazetteer, and OS Locator
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



This is a standard GeoDjango project. Install PostgreSQL and GeoDjango – I just followed the instructions.

Note that you should check the SRIDs – when I originally wrote this, not only was the Debian lenny PostGIS missing SRID 900913, as the GeoDjango docs tell you, but SRID 27700 (British National Grid, and therefore quite important in this application) was incorrect. After you’ve installed and got a PostGIS template, log in to it and update the proj4text column of SRID 27700 to include +datum=OSGB36 if it’s not already there.

Download the relevant OS data from their website (or mySociety’s mirror) – you want one or more of the 1:50k Gazetteer (place names), Code-Point Open (postcodes), and OS Locator (street names).

Once you’ve unzipped the files, you can import the data using the management commands included, e.g.

cat 50k.txt | ./manage.py import_places
cat oslocator.txt | ./manage.py import_roads
cat postcodes/*.csv | ./manage.py import_postcodes

Make sure DEBUG is False, otherwise you’ll soon run out of memory as it tries to remember all the SQL queries made.

That should be all you need to do – start up the dev web server, or whatever. The relevant bits of my nginx, for what it’s worth, are as follows:

upstream gazetteer_server {
    server unix:/tmp/gunicorn-gazetteer.sock fail_timeout=0;
server {
    root .../web;
    location / {
        try_files $uri @proxy_to_app;
    location @proxy_to_app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://gazetteer_server;

I use Debian’s gunicorn, so just have to specify a python and environment.PYTHONPATH in an /etc/gunicorn.d/ file.


  • The postcode and reverse geocoding work well, as they’re quite simple; the place and street name lookups could certainly be improved upon.
  • Nearest lookups are currently limited to the nearest mile; presumably if that returns no results, it should try again with a larger area, but I’m not sure of the best way of picking the initial/ subsequent distances.

Any comments or questions, do get in touch.