Geocoding and reverse-geocoding using the GeoNames datasets
In this recipe, you will write two PL/PostgreSQL PostGIS functions that will let you perform geocoding and reverse-geocoding using the GeoNames datasets.
GeoNames is a database of the place names of the world, containing over eight million records that are available for download free of charge. For the purpose of this recipe, you will download a part of the database, load it in PostGIS, and then use it within two functions to perform geocoding and reverse-geocoding. Geocoding is the process of finding coordinates from geographical data such as an address or a place name, while reverse-geocoding is the process of finding geographical data such as an address or place name from its coordinates.
You are going to write the two functions using PL/pgSQL, which adds on top of the PostgreSQL SQL commands the ability to tie more commands and queries together, a bunch of control structures, cursors, error management, and other goodness.