summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2010-03-25 20:01:40 +0000
committerJustin Bronn <jbronn@gmail.com>2010-03-25 20:01:40 +0000
commit917fb7c993374cabdde8f041bc4878d271d0ff42 (patch)
tree7e73d3b80e1a2787ea0cfea1c03b8335ade1729d
parent373daf587659d2aa396f25811d5f1d03b334d6bd (diff)
[1.1.X] Peform smarter version detection of GDAL so development versions are supported.
Backport of r12852 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12853 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/gis/gdal/__init__.py4
-rw-r--r--django/contrib/gis/gdal/libgdal.py23
-rw-r--r--django/contrib/gis/gdal/prototypes/geom.py10
3 files changed, 26 insertions, 11 deletions
diff --git a/django/contrib/gis/gdal/__init__.py b/django/contrib/gis/gdal/__init__.py
index b318850b28..5cb6876649 100644
--- a/django/contrib/gis/gdal/__init__.py
+++ b/django/contrib/gis/gdal/__init__.py
@@ -39,9 +39,9 @@ import sys
try:
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 = True
except:
HAS_GDAL, GEOJSON = False, False
diff --git a/django/contrib/gis/gdal/libgdal.py b/django/contrib/gis/gdal/libgdal.py
index 92e3165680..6589c5647c 100644
--- a/django/contrib/gis/gdal/libgdal.py
+++ b/django/contrib/gis/gdal/libgdal.py
@@ -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, m.group(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'])
+GDAL_VERSION = (GDAL_MAJOR_VERSION, GDAL_MINOR_VERSION, GDAL_SUBMINOR_VERSION)
+del _verinfo
+
+# GeoJSON support is available only in GDAL 1.5+.
+if GDAL_VERSION >= (1, 5):
+ GEOJSON = True
+else:
+ GEOJSON = False
+
diff --git a/django/contrib/gis/gdal/prototypes/geom.py b/django/contrib/gis/gdal/prototypes/geom.py
index e40f33e745..e002590e31 100644
--- a/django/contrib/gis/gdal/prototypes/geom.py
+++ b/django/contrib/gis/gdal/prototypes/geom.py
@@ -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
-else:
- GEOJSON = True
-
### Generation routines specific to this module ###
def env_func(f, argtypes):
"For getting OGREnvelopes."