Writing PostGIS functions with PL/Python
In this recipe, you will write a Python function for PostGIS using the PL/Python language. The PL/Python procedural language allows you to write PostgreSQL functions with the Python language.
You will use Python to query the http://openweathermap.org/Â web services, already used in a previous recipe, to get the weather for a PostGIS geometry from within a PostgreSQL function.
Getting ready
- Verify your PostgreSQL server installation has PL/Python support. In Windows, this should be already included, but this is not the default if you are using, for example, Ubuntu 16.04 LTS, so you will most likely need to install it:
$ sudo apt-get install postgresql-plpython-9.1
- Install PL/Python on the database (you could consider installing it in your
template1
database; in this way, every newly created database will have PL/Python support by default):
Note
You could alternatively add PL/Python support to your database, using the createlang
shell command (this is the only...