Database Reference
In-Depth Information
Writing
PostGIS
functions
with
PL/
Python
In this recipe, you will write a Python function for PostGIS using the PL/Python lan-
guage.ThePL/PythonprocedurallanguageallowsyoutowritePostgreSQLfunctions
with the Python language.
YouwillusePythonforqueryingthe openweathermap.org webservices,alreadyused
in a previous recipe, to get the weather for a PostGIS geometry from within a Post-
greSQL function.
Getting ready
1. VerifywhetheryourPostgreSQLserverinstallationhasPL/Pythonsupport.On
Windows,thisshouldbealreadyincluded,butthisisnotthedefaultifyouare
using, for example, Ubuntu 12.4 LTS, so you will most likely need to install it:
$ sudo apt-get install
postgresql-plpython-9.1
2. Install PL/Python on the database (you could consider installing it in your
template1 database;inthisway,everynewlycreateddatabasewillhavePL/
Python support by default):
Note
YoucouldalternativelyaddPL/Pythonsupporttoyourdatabaseusingthe
createlang shellcommand(thisistheonlywayifyouareusingaPost-
greSQL Version 9.1 or lower):
$ createlang plpythonu postgis_cookbook
$ psql -U me postgis_cookbookpsql (9.1.6,
server 9.1.8)Type "help" for help.
Search WWH ::




Custom Search