[postgis-users] Utility for creating geonames in PostGIS2

Jack Varga jack.varga at gmail.com
Tue Dec 11 12:38:22 PST 2012


Just sharing.  If using geonames you may find this useful.  Checks 
timestamps, downloads most current, creates database (includes schema), 
indexes, clusters, and assigns ownership.  Documentation included.  
Currently only grabs US postal codes but easily adaptable to grab any 
country's postal codes.  Makes a nice foundation for a simple location 
based service.  Works well with 2.x's indexed nearest neighbor searches 
as described here: 
http://blog.opengeo.org/2011/09/28/indexed-nearest-neighbour-search-in-postgis/.

For example, to find 10 closest hotels to downtown Boulder this query 
works well...

SELECT name, fcode
FROM geonames WHERE fcode = 'HTL'
ORDER BY geom <-> st_setsrid(st_makepoint(-105.27997,40.01789),4326)
LIMIT 10;

Code is here:  http://jvarga.github.com/geonames-for-postgis/

Comments/improvements encouraged.

Jack Varga
Boulder, Colorado


More information about the postgis-users mailing list