1 import os, sys |
1 import os, re, sys |
2 from ctypes import c_char_p, CDLL |
2 from ctypes import c_char_p, CDLL |
3 from ctypes.util import find_library |
3 from ctypes.util import find_library |
4 from django.contrib.gis.gdal.error import OGRException |
4 from django.contrib.gis.gdal.error import OGRException |
5 |
5 |
6 # Custom library path set? |
6 # Custom library path set? |
79 rel = _version_info('RELEASE_DATE') |
79 rel = _version_info('RELEASE_DATE') |
80 yy, mm, dd = map(int, (rel[0:4], rel[4:6], rel[6:8])) |
80 yy, mm, dd = map(int, (rel[0:4], rel[4:6], rel[6:8])) |
81 d = date_type(yy, mm, dd) |
81 d = date_type(yy, mm, dd) |
82 if date: return d |
82 if date: return d |
83 else: return d.strftime('%Y/%m/%d') |
83 else: return d.strftime('%Y/%m/%d') |
|
84 |
|
85 version_regex = re.compile(r'^(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<subminor>\d+))?') |
|
86 def gdal_version_info(): |
|
87 ver = gdal_version() |
|
88 m = version_regex.match(ver) |
|
89 if not m: raise OGRException('Could not parse GDAL version string "%s"' % ver) |
|
90 return dict([(key, m.group(key)) for key in ('major', 'minor', 'subminor')]) |
|
91 |
|
92 _verinfo = gdal_version_info() |
|
93 GDAL_MAJOR_VERSION = int(_verinfo['major']) |
|
94 GDAL_MINOR_VERSION = int(_verinfo['minor']) |
|
95 GDAL_SUBMINOR_VERSION = _verinfo['subminor'] and int(_verinfo['subminor']) |
|
96 GDAL_VERSION = (GDAL_MAJOR_VERSION, GDAL_MINOR_VERSION, GDAL_SUBMINOR_VERSION) |
|
97 del _verinfo |
|
98 |
|
99 # GeoJSON support is available only in GDAL 1.5+. |
|
100 if GDAL_VERSION >= (1, 5): |
|
101 GEOJSON = True |
|
102 else: |
|
103 GEOJSON = False |
|
104 |