2

I followed all the discussion and steps mentioned in GeoDjano GDAL Windows Post but trapped in another issue, I couldn't get GDAL available for GeoDjango.

In Python Console(C:\Python27), I am able to import gdal but GeoDjano says FALSE querying gdal.HAS_GDAL under Django/GeoDjango Apps Shell and get error on any Geometric Operations involving GDAL e.g. country.geom.geojson produces:

GEOSException: GeoJSON output only supported when GDAL is installed

I have Python2.7 installed as C:\Python27 with Path Environment Variable containing:

C:\Python27\; C:\Python27\bin; C:\Python27\scripts; C:\Program Files\GDAL;

and Other Environment Variables as:

GDAL_DATA         C:\Program Files\GDAL\gdal-data
GDAL_DRIVER_PATH  C:\Program Files\GDAL\gdalplugins
GDAL_LIBRARY_PATH C:\Program Files\GDAL

Also tried putting GDAL_LIBRARY_PATH="C:\\Program Files\\GDAL" in settings.py but didn't work.

I am using Windows 7 Ultimate x64, Python 2.7.3, Django 1.5.1 and tried Installing/Re Installing GDAL and Python GDAL Binding binaries.

Community
  • 1
  • 1
abdul-wahab
  • 2,182
  • 3
  • 21
  • 35

2 Answers2

1

Python is not detecting GDAL installation because of Windows Environmental Variables are not set correctly.

I only could solve this problem giving up OSGeo4w and using GDAL and MapServer.

You only need to edit libgdal.py (as said by Roberto Ribeiro if you are using GDAL version 2.x and probably is not your case.

0

The problem lies with how django calls the GDAL module: it looks for a specific GDAL DLL in your GDAL path, from a finite list of possible DLLs (gdal111, gdal110, gdal19, etc.).

Problem is, depending on which binary you install GDAL from, it may have different DLL names. For example, Gohlke's binaries generate a "gdal201.dll", which is not in the django list. Hence, it can't find it.

What you need to do is, first locate the name of the DLL in your GDAL installation (should be the largest file-size in your GDAL folder), then add it to the libgdal.py list, located at ..\Python27\lib\site-packages\django\contrib\gis\gdal\libgdal.py

The list is in line 26, and should read thus: lib_names = ['gdal111', 'gdal110', 'gdal19', 'gdal18', 'gdal17']

...or some variation of it, depending on your django version. Just add your DLL name to the list, and it should do fine.

Roberto Ribeiro
  • 123
  • 1
  • 7