Commit cdcdd131 authored by Claude Paroz's avatar Claude Paroz
Browse files

Dropped support for GDAL < 1.5

GDAL 1.5 has been released in December 2007.
parent 34340517
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -37,12 +37,12 @@
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, 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.geometries import OGRGeometry
    HAS_GDAL = True
except:
    HAS_GDAL, GEOJSON = False, False
    HAS_GDAL = False

try:
    from django.contrib.gis.gdal.envelope import Envelope
+5 −15
Original line number Diff line number Diff line
@@ -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.error import OGRException, OGRIndexError, SRSException
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

# Getting the ctypes prototype functions that interface w/the GDAL C library.
@@ -97,10 +97,7 @@ class OGRGeometry(GDALBase):
                else:
                    g = capi.from_wkt(byref(c_char_p(wkt_m.group('wkt'))), None, byref(c_void_p()))
            elif json_m:
                if GEOJSON:
                g = capi.from_json(geom_input)
                else:
                    raise NotImplementedError('GeoJSON input only supported on GDAL 1.5+.')
            else:
                # Seeing if the input is a valid short-hand string
                # (e.g., 'Point', 'POLYGON').
@@ -328,22 +325,15 @@ class OGRGeometry(GDALBase):
    @property
    def json(self):
        """
        Returns the GeoJSON representation of this Geometry (requires
        GDAL 1.5+).
        Returns the GeoJSON representation of this Geometry.
        """
        if GEOJSON:
        return capi.to_json(self.ptr)
        else:
            raise NotImplementedError('GeoJSON output only supported on GDAL 1.5+.')
    geojson = json

    @property
    def kml(self):
        "Returns the KML representation of the Geometry."
        if GEOJSON:
        return capi.to_kml(self.ptr, None)
        else:
            raise NotImplementedError('KML output only supported on GDAL 1.5+.')

    @property
    def wkb_size(self):
+1 −8
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ elif os.name == 'nt':
elif os.name == 'posix':
    # *NIX library names.
    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:
    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_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
+5 −10
Original line number Diff line number Diff line
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.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.generation import (const_string_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 ###

# GeoJSON routines, if supported.
if GEOJSON:
# GeoJSON routines.
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_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 = pnt_func(lgdal.OGR_G_GetX)
+0 −5
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ except ImportError:

from django.contrib.gis.gdal import (OGRGeometry, OGRGeomType, OGRException,
    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.utils import unittest

@@ -108,7 +107,6 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):

    def test01e_json(self):
        "Testing GeoJSON input/output."
        if not GEOJSON: return
        for g in self.geometries.json_geoms:
            geom = OGRGeometry(g.wkt)
            if not hasattr(g, 'not_equal'):
@@ -244,9 +242,6 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
            self.fail('Should have raised an OGRException!')
        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()
        self.assertEqual(10, poly.point_count) # Two closing points should've been added
        self.assertEqual(OGRGeometry('POINT(2.5 2.5)'), poly.centroid)
Loading