Version 7 (modified by adamfast, 8 years ago) (diff)

template_postgis is the "right" (referred to in many other places) name for the base db. Changing to reflect that convention.

These instructions apply for Debian Lenny and GeoDjango on django1.0 and postgresql-8.3

Packages Installation

Debian Lenny is shipped with the needed packages and defaults to python2.5

sudo apt-get install libgeos-3.0.0 proj postgis gdal-bin postgresql-8.3-postgis postgresql-8.3

Create a database template

This database could be used for recreating your geodjango powering databases

$ sudo su - postgres
$ createdb -E UTF8 template_postgis # Create the template spatial database.
$ createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
$ psql -d template_postgis -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql
$ psql -d template_postgis -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql
$ psql -d template_postgis # Enabling users to alter spatial tables.
template_postgis=# GRANT ALL ON geometry_columns TO PUBLIC;
template_postgis=# GRANT ALL ON spatial_ref_sys TO PUBLIC;

Testing the configuration

Make sure the new libraries are on the path, eventually logoff and sign in again.

The following tests should run flawlessly.

NOTE: you have to export GDAL_DATA variable:

export GDAL_DATA=/usr/share/gdal15

if you want you can set GDAL_DATA using gdal-config:

export GDAL_DATA=`gdal-config --datadir`

but you have to install libgdal1-dev deb package.

export DJANGO_SETTINGS_MODULE=myproject.settings
>>> from django.contrib.gis.gdal import HAS_GDAL
>>> print HAS_GDAL # Will be False if GDAL libraries are not found
>>> from django.contrib.gis.tests import test_gdal
>>> from django.contrib.gis.tests import test_geos

Creating a database

Now when creating a new database, use template_postgis as template (substitute in the appropriate database owner and the database name:

sudo su postgres
createdb -T template_postgis -O db_user db_name


If you hit errors, please refer to GeoDjangoInstall

Back to Top