Clone wiki

django-locals / Home

GeoNames Local

So, I needed a way to find "surrounding suburbs", and a friend put me onto GeoNames. Fantastic site!

I just needed a way to look up a suburb/post code, and then to ask "What are the nearest N", or "Which are within X km of Y"?


Remember, this requires GeoDjango. So, for us running Postgres, you need PostGIS installed. This can be easy, so don't sweat it.

Source Data

The data are read from files you can download at GeoNames dump ZIPs here.

There are two source dumps available -- you want the /zip/ not /dump/.

Once you have 'local' installed as a Django app, you can load the data using:

./ geonames_load AU.txt

And it does the rest. I do not yet have an "update" feature -- still sorting the logic on that.

Model Methods

Location.surrounding_suburbs(distance, unit='km')

Returns a queryset of Locations within the distance from this Location.

Template Tags & Filters

Load the lib "geonames" and you can use the postcode_to_suburb filter. It will return a comma-separated list of Suburb names that match the postcode.

  { { address.postcode|postcode_to_suburb } }

In my first use, I pushed in "3148" and got out "Chadstone, Holmesglen".