Robot friendly script to install PostGIS for use with Django's Geo framework.

Django's GIS framework is superb, and really fairly simple to use, but it can be a bit of a pain to get PostGIS and associated bits installed.

The instructions here were a great help, but I needed to update a few things to get them working for Postgres9.1. I've put everything into a bash script which will do everything for you, here, and there's a few other notes below.

PostGIS compilation errors

Attempting to compile and install PostGIS gave me an error:

cannot create directory \`/usr/share/postgresql/9.1/contrib': No such
file or directory

I had the postgresql-contrib-9.1 package installed, and couldn't see why we didn't have perms to create this directory, so I created it:

sudo mkdir -p '/usr/share/postgresql/9.1/contrib/postgis-1.5'

Then ran it again, and it all installed fine. It appears that the contrib location has moved. I get the impression there's probably a better way to fix this.

Django 1.3 and standard_conforming_string

When attempting to use the models with Django 1.3 you may well see:

django.db.utils.DatabaseError: invalid byte sequence for encoding "UTF8": 0x00

This is due an incompatibility between a change in Postgres 9.1's new default config and Django 1.3. It requires the postgres setting for standard_conforming_string to be off, but it's switched on by default now. You can either set your standard_conforming_string = off in postgres.conf, or you can patch Django. See here, https://code.djangoproject.com/ticket/16778.

This is changed/fixed in trunk for Django 1.4.

Hope that's useful to someone.

Rolo.

comments powered by Disqus

Pingbacks

Pingbacks are open.