Recently both Django 1.4 and PostGIS-2.0 were released and I needed to setup a new development environment.
However, since the release dates of both were pretty close, it looks like django-1.4 didn't manage to get support for Postgis-2.0 into the 1.4 release and the following error occures:
ERROR: operator class "gist_geometry_ops" does not accept access method "gist"
Luckily this is already identified as an issue. (See Ticket #16455 )
While the patch hasn't been accepted yet, it does appear to work for me, so at least you can use geometry columns in PostGIS-2.0 when you apply the patch.
The gdal-data folder is ONLY installed with postgis-2.0, and is not found in postgis-1.5.
This folder is needed to perform projection translations and the python GDAL library also needs this information.
Once this is done you should be able to create/syncdb for models that contain geometry fields.
Almost every time I setup or someone in my team sets up a new development environment someone has an issue getting GDAL to work. In my case I need some of the raster features available in the stock gdal package which are NOT available in the django version (see note). So I nned to install the standard python GDAL package in pypi.
Getting this to work with django was a long process of trial and error. Here's what I did (on win7):
The 1.9.0 windows binaries are available at http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
- This will install all necessary GDAL dlls.
Next, create the directory C:\gdallibs.
Then copy all the DLLs that were installed in C:\Python27\Lib\site-packages\osgeo to C:\gdallibs
Add C:\gdallibs to the PATH environment variable.
django-1.4 does not yet have support for gdal-1.9.0 and cannot find the 1.9 library. Overwrite the local django.contrib.gis.gdal.libgdal with this updated version libgdal.py
- This adds gdal1.9 to the library search and also allows configuration of GDAL_LIBRARY_PATH as an environment variable. (Although, I found it was not needed once C:\gdallibs was created and added to the PATH.
Confirm that gdal.HAS_GDAL+ and *gdal.GEOJSON are True:
>>> from django.contrib.gis import gdal
You may need to open a NEW console for the updated PATH environment variable to take effect.