Database Reference
In-Depth Information
Geocoding with geopy and PL/Python
Inthisrecipe,youwillgeocodeaddressesusingawebgeocodingAPIsuchasGoogle
Maps,Yahoo!Maps,geocoder.us,GeoNames,andsoon.BesuretoreadtheTerms
of Services of these APIs carefully before using them in production.
The geopy Pythonlibrary( http://code.google.com/p/geopy/ )offersaconvenient,uni-
form access to all of these web services. Therefore, you will use it to create a PL/
PythonPostgreSQLfunctionthatcanbeusedinyourSQLcommandstoqueryallof
these engines.
Getting ready
1. Install geopy globally.(Youcannotuseavirtualenvironmentinthiscase,as
the user running the PostgreSQL service needs to access it on its Python
path.)
In a Debian/Ubuntu box, it is as easy as typing the following:
$ sudo pip install geopy
In Windows, you can use the following command:
> pip install geopy
2. If you still did not use PL/Python, verify whether your PostgreSQL server in-
stallation supports it. The Windows EDB installer should already include this
support,butthisisnotthedefaultifyouareusing,forexample,Ubuntu12.4
LTS, so you most likely need to install it:
$ sudo apt-get install
postgresql-plpython-9.1
3. InstallPL/Pythononthedatabase(youcouldconsiderinstallingitinthe tem-
plate1 database; this way, every newly created database will have PL/
Python support by default):
Search WWH ::




Custom Search