Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Peform smarter version detection of GDAL so development versions are …

…supported.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12852 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9b50ec81a388d636c5e7d40e118a5bb6388ba21d 1 parent f13014b
@jbronn jbronn authored
View
4 django/contrib/gis/gdal/__init__.py
@@ -37,9 +37,9 @@
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
View
23 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
+
View
10 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."
Please sign in to comment.
Something went wrong with that request. Please try again.