Dropped support for GDAL < 1.5

GDAL 1.5 has been released in December 2007.
This commit is contained in:
Claude Paroz 2012-07-15 21:07:02 +02:00
parent 34340517fc
commit cdcdd131da
12 changed files with 29 additions and 52 deletions

View File

@ -37,12 +37,12 @@
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, GEOJSON, GDAL_VERSION from django.contrib.gis.gdal.libgdal import gdal_version, gdal_full_version, gdal_release_date, 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 from django.contrib.gis.gdal.geometries import OGRGeometry
HAS_GDAL = True HAS_GDAL = True
except: except:
HAS_GDAL, GEOJSON = False, False HAS_GDAL = False
try: try:
from django.contrib.gis.gdal.envelope import Envelope from django.contrib.gis.gdal.envelope import Envelope

View File

@ -48,7 +48,7 @@ from django.contrib.gis.gdal.base import GDALBase
from django.contrib.gis.gdal.envelope import Envelope, OGREnvelope from django.contrib.gis.gdal.envelope import Envelope, OGREnvelope
from django.contrib.gis.gdal.error import OGRException, OGRIndexError, SRSException from django.contrib.gis.gdal.error import OGRException, OGRIndexError, SRSException
from django.contrib.gis.gdal.geomtype import OGRGeomType from django.contrib.gis.gdal.geomtype import OGRGeomType
from django.contrib.gis.gdal.libgdal import GEOJSON, GDAL_VERSION from django.contrib.gis.gdal.libgdal import GDAL_VERSION
from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform
# Getting the ctypes prototype functions that interface w/the GDAL C library. # Getting the ctypes prototype functions that interface w/the GDAL C library.
@ -97,10 +97,7 @@ class OGRGeometry(GDALBase):
else: else:
g = capi.from_wkt(byref(c_char_p(wkt_m.group('wkt'))), None, byref(c_void_p())) g = capi.from_wkt(byref(c_char_p(wkt_m.group('wkt'))), None, byref(c_void_p()))
elif json_m: elif json_m:
if GEOJSON: g = capi.from_json(geom_input)
g = capi.from_json(geom_input)
else:
raise NotImplementedError('GeoJSON input only supported on GDAL 1.5+.')
else: else:
# Seeing if the input is a valid short-hand string # Seeing if the input is a valid short-hand string
# (e.g., 'Point', 'POLYGON'). # (e.g., 'Point', 'POLYGON').
@ -328,22 +325,15 @@ class OGRGeometry(GDALBase):
@property @property
def json(self): def json(self):
""" """
Returns the GeoJSON representation of this Geometry (requires Returns the GeoJSON representation of this Geometry.
GDAL 1.5+).
""" """
if GEOJSON: return capi.to_json(self.ptr)
return capi.to_json(self.ptr)
else:
raise NotImplementedError('GeoJSON output only supported on GDAL 1.5+.')
geojson = json geojson = json
@property @property
def kml(self): def kml(self):
"Returns the KML representation of the Geometry." "Returns the KML representation of the Geometry."
if GEOJSON: return capi.to_kml(self.ptr, None)
return capi.to_kml(self.ptr, None)
else:
raise NotImplementedError('KML output only supported on GDAL 1.5+.')
@property @property
def wkb_size(self): def wkb_size(self):

View File

@ -19,7 +19,7 @@ elif os.name == 'nt':
elif os.name == 'posix': elif os.name == 'posix':
# *NIX library names. # *NIX library names.
lib_names = ['gdal', 'GDAL', 'gdal1.9.0', 'gdal1.8.0', 'gdal1.7.0', lib_names = ['gdal', 'GDAL', 'gdal1.9.0', 'gdal1.8.0', 'gdal1.7.0',
'gdal1.6.0', 'gdal1.5.0', 'gdal1.4.0'] 'gdal1.6.0', 'gdal1.5.0']
else: else:
raise OGRException('Unsupported OS "%s"' % os.name) raise OGRException('Unsupported OS "%s"' % os.name)
@ -97,10 +97,3 @@ GDAL_MINOR_VERSION = int(_verinfo['minor'])
GDAL_SUBMINOR_VERSION = _verinfo['subminor'] and int(_verinfo['subminor']) GDAL_SUBMINOR_VERSION = _verinfo['subminor'] and int(_verinfo['subminor'])
GDAL_VERSION = (GDAL_MAJOR_VERSION, GDAL_MINOR_VERSION, GDAL_SUBMINOR_VERSION) GDAL_VERSION = (GDAL_MAJOR_VERSION, GDAL_MINOR_VERSION, GDAL_SUBMINOR_VERSION)
del _verinfo del _verinfo
# GeoJSON support is available only in GDAL 1.5+.
if GDAL_VERSION >= (1, 5):
GEOJSON = True
else:
GEOJSON = False

View File

@ -1,6 +1,6 @@
from ctypes import c_char_p, c_double, c_int, c_void_p, POINTER from ctypes import c_char_p, c_double, c_int, 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, GEOJSON from django.contrib.gis.gdal.libgdal import lgdal
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 (const_string_output, from django.contrib.gis.gdal.prototypes.generation import (const_string_output,
double_output, geom_output, int_output, srs_output, string_output, void_output) double_output, geom_output, int_output, srs_output, string_output, void_output)
@ -25,15 +25,10 @@ def topology_func(f):
### OGR_G ctypes function prototypes ### ### OGR_G ctypes function prototypes ###
# GeoJSON routines, if supported. # GeoJSON routines.
if GEOJSON: from_json = geom_output(lgdal.OGR_G_CreateGeometryFromJson, [c_char_p])
from_json = geom_output(lgdal.OGR_G_CreateGeometryFromJson, [c_char_p]) to_json = string_output(lgdal.OGR_G_ExportToJson, [c_void_p], str_result=True)
to_json = string_output(lgdal.OGR_G_ExportToJson, [c_void_p], str_result=True) to_kml = string_output(lgdal.OGR_G_ExportToKML, [c_void_p, c_char_p], str_result=True)
to_kml = string_output(lgdal.OGR_G_ExportToKML, [c_void_p, c_char_p], str_result=True)
else:
from_json = False
to_json = False
to_kml = False
# GetX, GetY, GetZ all return doubles. # GetX, GetY, GetZ all return doubles.
getx = pnt_func(lgdal.OGR_G_GetX) getx = pnt_func(lgdal.OGR_G_GetX)

View File

@ -6,7 +6,6 @@ except ImportError:
from django.contrib.gis.gdal import (OGRGeometry, OGRGeomType, OGRException, from django.contrib.gis.gdal import (OGRGeometry, OGRGeomType, OGRException,
OGRIndexError, SpatialReference, CoordTransform, GDAL_VERSION) OGRIndexError, SpatialReference, CoordTransform, GDAL_VERSION)
from django.contrib.gis.gdal.prototypes.geom import GEOJSON
from django.contrib.gis.geometry.test_data import TestDataMixin from django.contrib.gis.geometry.test_data import TestDataMixin
from django.utils import unittest from django.utils import unittest
@ -108,7 +107,6 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
def test01e_json(self): def test01e_json(self):
"Testing GeoJSON input/output." "Testing GeoJSON input/output."
if not GEOJSON: return
for g in self.geometries.json_geoms: for g in self.geometries.json_geoms:
geom = OGRGeometry(g.wkt) geom = OGRGeometry(g.wkt)
if not hasattr(g, 'not_equal'): if not hasattr(g, 'not_equal'):
@ -244,9 +242,6 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
self.fail('Should have raised an OGRException!') self.fail('Should have raised an OGRException!')
print("\nEND - expecting IllegalArgumentException; safe to ignore.\n") print("\nEND - expecting IllegalArgumentException; safe to ignore.\n")
# Closing the rings -- doesn't work on GDAL versions 1.4.1 and below:
# http://trac.osgeo.org/gdal/ticket/1673
if GDAL_VERSION <= (1, 4, 1): return
poly.close_rings() poly.close_rings()
self.assertEqual(10, poly.point_count) # Two closing points should've been added self.assertEqual(10, poly.point_count) # Two closing points should've been added
self.assertEqual(OGRGeometry('POINT(2.5 2.5)'), poly.centroid) self.assertEqual(OGRGeometry('POINT(2.5 2.5)'), poly.centroid)

View File

@ -10,7 +10,6 @@ except ImportError:
# A 'dummy' gdal module. # A 'dummy' gdal module.
class GDALInfo(object): class GDALInfo(object):
HAS_GDAL = False HAS_GDAL = False
GEOJSON = False
gdal = GDALInfo() gdal = GDALInfo()
# NumPy supported? # NumPy supported?

View File

@ -65,7 +65,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
elif hex_regex.match(geo_input): elif hex_regex.match(geo_input):
# Handling HEXEWKB input. # Handling HEXEWKB input.
g = wkb_r().read(geo_input) g = wkb_r().read(geo_input)
elif gdal.GEOJSON and json_regex.match(geo_input): elif gdal.HAS_GDAL and json_regex.match(geo_input):
# Handling GeoJSON input. # Handling GeoJSON input.
g = wkb_r().read(gdal.OGRGeometry(geo_input).wkb) g = wkb_r().read(gdal.OGRGeometry(geo_input).wkb)
else: else:
@ -409,13 +409,12 @@ class GEOSGeometry(GEOSBase, ListMixin):
@property @property
def json(self): def json(self):
""" """
Returns GeoJSON representation of this Geometry if GDAL 1.5+ Returns GeoJSON representation of this Geometry if GDAL is installed.
is installed.
""" """
if gdal.GEOJSON: if gdal.HAS_GDAL:
return self.ogr.json return self.ogr.json
else: else:
raise GEOSException('GeoJSON output only supported on GDAL 1.5+.') raise GEOSException('GeoJSON output only supported when GDAL is installed.')
geojson = json geojson = json
@property @property

View File

@ -196,7 +196,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
self.assertEqual(srid, poly.shell.srid) self.assertEqual(srid, poly.shell.srid)
self.assertEqual(srid, fromstr(poly.ewkt).srid) # Checking export self.assertEqual(srid, fromstr(poly.ewkt).srid) # Checking export
@unittest.skipUnless(gdal.HAS_GDAL and gdal.GEOJSON, "gdal >= 1.5 is required") @unittest.skipUnless(gdal.HAS_GDAL, "gdal is required")
def test_json(self): def test_json(self):
"Testing GeoJSON input/output (via GDAL)." "Testing GeoJSON input/output (via GDAL)."
for g in self.geometries.json_geoms: for g in self.geometries.json_geoms:

View File

@ -71,6 +71,7 @@ class GeometryFieldTest(unittest.TestCase):
for wkt in ('POINT(5 23)', 'MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 'LINESTRING(0 0, 1 1)'): for wkt in ('POINT(5 23)', 'MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 'LINESTRING(0 0, 1 1)'):
self.assertEqual(GEOSGeometry(wkt), fld.to_python(wkt)) self.assertEqual(GEOSGeometry(wkt), fld.to_python(wkt))
# but raises a ValidationError for any other string # but raises a ValidationError for any other string
import pdb; pdb.set_trace()
for wkt in ('POINT(5)', 'MULTI POLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 'BLAH(0 0, 1 1)'): for wkt in ('POINT(5)', 'MULTI POLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 'BLAH(0 0, 1 1)'):
self.assertRaises(forms.ValidationError, fld.to_python, wkt) self.assertRaises(forms.ValidationError, fld.to_python, wkt)

View File

@ -447,7 +447,7 @@ systems and coordinate transformation::
This object is a wrapper for the `OGR Geometry`__ class. This object is a wrapper for the `OGR Geometry`__ class.
These objects are instantiated directly from the given ``geom_input`` These objects are instantiated directly from the given ``geom_input``
parameter, which may be a string containing WKT or HEX, a ``buffer`` parameter, which may be a string containing WKT, HEX, GeoJSON, a ``buffer``
containing WKB data, or an :class:`OGRGeomType` object. These objects containing WKB data, or an :class:`OGRGeomType` object. These objects
are also returned from the :class:`Feature.geom` attribute, when are also returned from the :class:`Feature.geom` attribute, when
reading vector data from :class:`Layer` (which is in turn a part of reading vector data from :class:`Layer` (which is in turn a part of

View File

@ -81,7 +81,7 @@ Program Description Required
======================== ==================================== ================================ ========================== ======================== ==================================== ================================ ==========================
:ref:`GEOS <ref-geos>` Geometry Engine Open Source Yes 3.3, 3.2, 3.1, 3.0 :ref:`GEOS <ref-geos>` Geometry Engine Open Source Yes 3.3, 3.2, 3.1, 3.0
`PROJ.4`_ Cartographic Projections library Yes (PostgreSQL and SQLite only) 4.7, 4.6, 4.5, 4.4 `PROJ.4`_ Cartographic Projections library Yes (PostgreSQL and SQLite only) 4.7, 4.6, 4.5, 4.4
:ref:`GDAL <ref-gdal>` Geospatial Data Abstraction Library No (but, required for SQLite) 1.8, 1.7, 1.6, 1.5, 1.4 :ref:`GDAL <ref-gdal>` Geospatial Data Abstraction Library No (but, required for SQLite) 1.9, 1.8, 1.7, 1.6, 1.5
:ref:`GeoIP <ref-geoip>` IP-based geolocation library No 1.4 :ref:`GeoIP <ref-geoip>` IP-based geolocation library No 1.4
`PostGIS`__ Spatial extensions for PostgreSQL Yes (PostgreSQL only) 1.5, 1.4, 1.3 `PostGIS`__ Spatial extensions for PostgreSQL Yes (PostgreSQL only) 1.5, 1.4, 1.3
`SpatiaLite`__ Spatial extensions for SQLite Yes (SQLite only) 3.0, 2.4, 2.3 `SpatiaLite`__ Spatial extensions for SQLite Yes (SQLite only) 3.0, 2.4, 2.3
@ -270,9 +270,9 @@ supports :ref:`GDAL's vector data <ref-gdal>` capabilities [#]_.
First download the latest GDAL release version and untar the archive:: First download the latest GDAL release version and untar the archive::
$ wget http://download.osgeo.org/gdal/gdal-1.8.1.tar.gz $ wget http://download.osgeo.org/gdal/gdal-1.9.1.tar.gz
$ tar xzf gdal-1.8.1.tar.gz $ tar xzf gdal-1.9.1.tar.gz
$ cd gdal-1.8.1 $ cd gdal-1.9.1
Configure, make and install:: Configure, make and install::

View File

@ -177,6 +177,11 @@ autocommit behavior was never restored. This bug is now fixed in 1.5. While
this is only a bug fix, it is worth checking your applications behavior if this is only a bug fix, it is worth checking your applications behavior if
you are using PostgreSQL together with the autocommit option. you are using PostgreSQL together with the autocommit option.
Miscellaneous
~~~~~~~~~~~~~
* GeoDjango dropped support for GDAL < 1.5
Features deprecated in 1.5 Features deprecated in 1.5
========================== ==========================