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
This commit is contained in:
parent
f13014b7e2
commit
9b50ec81a3
|
@ -37,9 +37,9 @@
|
||||||
try:
|
try:
|
||||||
from django.contrib.gis.gdal.driver import Driver
|
from django.contrib.gis.gdal.driver import Driver
|
||||||
from django.contrib.gis.gdal.datasource import DataSource
|
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.srs import SpatialReference, CoordTransform
|
||||||
from django.contrib.gis.gdal.geometries import OGRGeometry, GEOJSON
|
from django.contrib.gis.gdal.geometries import OGRGeometry
|
||||||
HAS_GDAL = True
|
HAS_GDAL = True
|
||||||
except:
|
except:
|
||||||
HAS_GDAL, GEOJSON = False, False
|
HAS_GDAL, GEOJSON = False, False
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import os, sys
|
import os, re, sys
|
||||||
from ctypes import c_char_p, CDLL
|
from ctypes import c_char_p, CDLL
|
||||||
from ctypes.util import find_library
|
from ctypes.util import find_library
|
||||||
from django.contrib.gis.gdal.error import OGRException
|
from django.contrib.gis.gdal.error import OGRException
|
||||||
|
@ -81,3 +81,24 @@ def gdal_release_date(date=False):
|
||||||
d = date_type(yy, mm, dd)
|
d = date_type(yy, mm, dd)
|
||||||
if date: return d
|
if date: return d
|
||||||
else: return d.strftime('%Y/%m/%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
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
|
import re
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from ctypes import c_char, c_char_p, c_double, c_int, c_ubyte, c_void_p, POINTER
|
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.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.errcheck import check_bool, check_envelope
|
||||||
from django.contrib.gis.gdal.prototypes.generation import \
|
from django.contrib.gis.gdal.prototypes.generation import \
|
||||||
const_string_output, double_output, geom_output, int_output, \
|
const_string_output, double_output, geom_output, int_output, \
|
||||||
srs_output, string_output, void_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 ###
|
### Generation routines specific to this module ###
|
||||||
def env_func(f, argtypes):
|
def env_func(f, argtypes):
|
||||||
"For getting OGREnvelopes."
|
"For getting OGREnvelopes."
|
||||||
|
|
Loading…
Reference in New Issue