diff --git a/django/contrib/gis/gdal/__init__.py b/django/contrib/gis/gdal/__init__.py index 5ef8a859274..cc47ae9bc29 100644 --- a/django/contrib/gis/gdal/__init__.py +++ b/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 diff --git a/django/contrib/gis/gdal/libgdal.py b/django/contrib/gis/gdal/libgdal.py index 92e3165680a..6589c5647c2 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\d+)\.(?P\d+)(\.(?P\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 e40f33e7455..e002590e31a 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."