Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

[1.1.X] Peform smarter version detection of GDAL so development versi…

…ons are supported.

Backport of r12852 from trunk.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 373daf5 commit 917fb7c993374cabdde8f041bc4878d271d0ff42 @jbronn jbronn committed
4 django/contrib/gis/gdal/
@@ -39,9 +39,9 @@
from django.contrib.gis.gdal.driver import Driver
from django.contrib.gis.gdal.datasource import DataSource
- from django.contrib.gis.gdal.libgdal import gdal_version, gdal_full_version, gdal_release_date
+ from django.contrib.gis.gdal.libgdal import gdal_version, gdal_full_version, gdal_release_date, GEOJSON, GDAL_VERSION
from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform
- from django.contrib.gis.gdal.geometries import OGRGeometry, GEOJSON
+ from django.contrib.gis.gdal.geometries import OGRGeometry
HAS_GDAL, GEOJSON = False, False
23 django/contrib/gis/gdal/
@@ -1,4 +1,4 @@
-import os, sys
+import os, re, sys
from ctypes import c_char_p, CDLL
from ctypes.util import find_library
from django.contrib.gis.gdal.error import OGRException
@@ -81,3 +81,24 @@ def gdal_release_date(date=False):
d = date_type(yy, mm, dd)
if date: return d
else: return d.strftime('%Y/%m/%d')
+version_regex = re.compile(r'^(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<subminor>\d+))?')
+def gdal_version_info():
+ ver = gdal_version()
+ m = version_regex.match(ver)
+ if not m: raise OGRException('Could not parse GDAL version string "%s"' % ver)
+ return dict([(key, for key in ('major', 'minor', 'subminor')])
+_verinfo = gdal_version_info()
+GDAL_MAJOR_VERSION = int(_verinfo['major'])
+GDAL_MINOR_VERSION = int(_verinfo['minor'])
+GDAL_SUBMINOR_VERSION = _verinfo['subminor'] and int(_verinfo['subminor'])
+del _verinfo
+# GeoJSON support is available only in GDAL 1.5+.
+if GDAL_VERSION >= (1, 5):
+ GEOJSON = True
+ GEOJSON = False
10 django/contrib/gis/gdal/prototypes/
@@ -1,19 +1,13 @@
+import re
from datetime import date
from ctypes import c_char, c_char_p, c_double, c_int, c_ubyte, c_void_p, POINTER
from django.contrib.gis.gdal.envelope import OGREnvelope
-from django.contrib.gis.gdal.libgdal import lgdal, gdal_version
+from django.contrib.gis.gdal.libgdal import lgdal, GEOJSON
from django.contrib.gis.gdal.prototypes.errcheck import check_bool, check_envelope
from django.contrib.gis.gdal.prototypes.generation import \
const_string_output, double_output, geom_output, int_output, \
srs_output, string_output, void_output
-# Some prototypes need to be aware of what version GDAL we have.
-major, minor = map(int, gdal_version().split('.')[:2])
-if major <= 1 and minor <= 4:
- GEOJSON = False
- GEOJSON = True
### Generation routines specific to this module ###
def env_func(f, argtypes):
"For getting OGREnvelopes."

0 comments on commit 917fb7c

Please sign in to comment.
Something went wrong with that request. Please try again.