Adapted from: http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS20Ubuntu1204src
Spatially enabling a database
With PostgreSQL 9.1, there are two methods to add PostGIS functionality to a database: - using extensions, - using enabler scripts.
PostGIS Extension for PostgreSQL
Spatially enabling a database using extensions is a new feature of PostgreSQL 9.1. Connect to your database using pgAdmin or psql, and run the following commands. To add postgis with raster support: CREATE EXTENSION postgis; To add topology support, a second extension can be created on the database: CREATE EXTENSION postgis_topology;
Notes
- No PostGIS topology functionalities are yet available from GeoDjango, so the creation of the postgis_topology extension is entirely optional - Raster is required for the extension installation method for PostgreSQL.
Install from sources on Ubuntu
Here we avoid postgis_topology installation; to have topology installed, follow:
http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS20Ubuntu1204src
$ sudo apt-get install libxml2-dev libproj-dev $ sudo apt-get install libgdal1-dev $ wget http://download.osgeo.org/postgis/source/postgis-2.0.4.tar.gz $ tar xfz postgis-2.0.4.tar.gz $ cd postgis-2.0.4 $ ./configure --without-topology $ make $ sudo make install $ sudo ldconfig $ sudo make comments-install
Note per l’esecuzione di unit tests in Django
- Django unit tests runner uses CREATE EXTENSION to build test database when settings specify 'ENGINE'= django.contrib.gis.db.backends.postgis' - L'utente del db deve essere superuser (per postgres) al fine di evitare l'errore: DatabaseError: permission denied to create extension "postgis" HINT: Must be superuser to create this extension. quindi: psql# alter role superuser;
Fix per Postgresql 9.3
# .../postgis-2.0.x/postgis/geometry_estimate.c add: //add #if POSTGIS_PGSQL_VERSION >= 93 #include "access/htup_details.h" #endif then repeat make, make install See: http://stackoverflow.com/questions/16644163/solved-postgis-2-0-so-undefined-symbol-getstruct