Django with SQLite as a geospatial database

For testing purposes I wanted to use SQLite to speed up the tests, so this post sums up what I had to do.

Most of it is inspired by GeoDjango with spatialite on OSX.

Download pysqlite:

wget http://pysqlite.googlecode.com/files/pysqlite-2.6.3.tar.gz
tar -xzvf pysqlite-2.6.3.tar.gz
cd pysqlite-2.6.3

Edit setup.cfg and out comment define=SQLITE_OMIT_LOAD_EXTENSION so it looks like:

#define=SQLITE_OMIT_LOAD_EXTENSION

Build it:

python setup.py build_static
python setup.py install

Create spatial metadata tables:

touch /tmp/test.db
spatialite /tmp/test.db "SELECT InitSpatialMetaData();"

Don’t mind the error table spatial_ref_sys already exists.

Now back to your project and in your relevant settings.py you need:

DATABASES['default'] = {
    'ENGINE': 'django.contrib.gis.db.backends.spatialite',
    'NAME': '/tmp/test.db'
}

Done. I hope?

Notes

  1. technotes posted this