diff --git a/django/contrib/gis/geos/__init__.py b/django/contrib/gis/geos/__init__.py index 76cb1d6446..7f26690aec 100644 --- a/django/contrib/gis/geos/__init__.py +++ b/django/contrib/gis/geos/__init__.py @@ -31,7 +31,7 @@ from django.contrib.gis.geos.base import GEOSGeometry, wkt_regex, hex_regex from django.contrib.gis.geos.geometries import Point, LineString, LinearRing, Polygon, HAS_NUMPY from django.contrib.gis.geos.collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon -from django.contrib.gis.geos.error import GEOSException, GEOSGeometryIndexError +from django.contrib.gis.geos.error import GEOSException, GEOSIndexError from django.contrib.gis.geos.libgeos import geos_version def fromfile(file_name): diff --git a/django/contrib/gis/geos/base.py b/django/contrib/gis/geos/base.py index 694daf304c..1a2555bc16 100644 --- a/django/contrib/gis/geos/base.py +++ b/django/contrib/gis/geos/base.py @@ -9,7 +9,7 @@ from types import StringType, UnicodeType, IntType, FloatType, BufferType # GEOS-related dependencies. from django.contrib.gis.geos.coordseq import GEOSCoordSeq -from django.contrib.gis.geos.error import GEOSException, GEOSGeometryIndexError +from django.contrib.gis.geos.error import GEOSException from django.contrib.gis.geos.libgeos import GEOM_PTR # All other functions in this module come from the ctypes @@ -121,44 +121,21 @@ class GEOSGeometry(object): "Returns the union of this Geometry and the other." return self.union(other) - # g1 |= g2 - def __ior__(self, other): - "Reassigns this Geometry to the union of this Geometry and the other." - return self.union(other) - # g = g1 & g2 def __and__(self, other): "Returns the intersection of this Geometry and the other." return self.intersection(other) - # g1 &= g2 - def __iand__(self, other): - "Reassigns this Geometry to the intersection of this Geometry and the other." - return self.intersection(other) - # g = g1 - g2 def __sub__(self, other): "Return the difference this Geometry and the other." return self.difference(other) - # g1 -= g2 - def __isub__(self, other): - "Reassigns this Geometry to the difference of this Geometry and the other." - return self.difference(other) - # g = g1 ^ g2 def __xor__(self, other): "Return the symmetric difference of this Geometry and the other." return self.sym_difference(other) - # g1 ^= g2 - def __ixor__(self, other): - """ - Reassigns this Geometry to the symmetric difference of this Geometry - and the other. - """ - return self.sym_difference(other) - #### Coordinate Sequence Routines #### @property def has_cs(self): diff --git a/django/contrib/gis/geos/collections.py b/django/contrib/gis/geos/collections.py index 51c4d7a135..5ca7e57909 100644 --- a/django/contrib/gis/geos/collections.py +++ b/django/contrib/gis/geos/collections.py @@ -5,7 +5,7 @@ from ctypes import c_int, c_uint, byref from types import TupleType, ListType from django.contrib.gis.geos.base import GEOSGeometry -from django.contrib.gis.geos.error import GEOSException, GEOSGeometryIndexError +from django.contrib.gis.geos.error import GEOSException, GEOSIndexError from django.contrib.gis.geos.geometries import Point, LineString, LinearRing, Polygon from django.contrib.gis.geos.libgeos import get_pointer_arr, GEOM_PTR from django.contrib.gis.geos.prototypes import create_collection, destroy_geom, geom_clone, geos_typeid, get_cs, get_geomn @@ -80,7 +80,7 @@ class GeometryCollection(GEOSGeometry): def _checkindex(self, index): "Checks the given geometry index." if index < 0 or index >= self.num_geom: - raise GEOSGeometryIndexError('invalid GEOS Geometry index: %s' % str(index)) + raise GEOSIndexError('invalid GEOS Geometry index: %s' % str(index)) @property def kml(self): diff --git a/django/contrib/gis/geos/coordseq.py b/django/contrib/gis/geos/coordseq.py index ef0fdbec6f..8cbf25c0f2 100644 --- a/django/contrib/gis/geos/coordseq.py +++ b/django/contrib/gis/geos/coordseq.py @@ -5,7 +5,7 @@ """ from ctypes import c_double, c_uint, byref from types import ListType, TupleType -from django.contrib.gis.geos.error import GEOSException, GEOSGeometryIndexError +from django.contrib.gis.geos.error import GEOSException, GEOSIndexError from django.contrib.gis.geos.libgeos import CS_PTR, HAS_NUMPY from django.contrib.gis.geos.prototypes import cs_clone, cs_getdims, cs_getordinate, cs_getsize, cs_setordinate if HAS_NUMPY: from numpy import ndarray @@ -69,7 +69,7 @@ class GEOSCoordSeq(object): "Checks the given index." sz = self.size if (sz < 1) or (index < 0) or (index >= sz): - raise GEOSGeometryIndexError('invalid GEOS Geometry index: %s' % str(index)) + raise GEOSIndexError('invalid GEOS Geometry index: %s' % str(index)) def _checkdim(self, dim): "Checks the given dimension." diff --git a/django/contrib/gis/geos/error.py b/django/contrib/gis/geos/error.py index 422699da18..46bdfe691a 100644 --- a/django/contrib/gis/geos/error.py +++ b/django/contrib/gis/geos/error.py @@ -7,7 +7,7 @@ class GEOSException(Exception): "The base GEOS exception, indicates a GEOS-related error." pass -class GEOSGeometryIndexError(GEOSException, KeyError): +class GEOSIndexError(GEOSException, KeyError): """ This exception is raised when an invalid index is encountered, and has the 'silent_variable_feature' attribute set to true. This ensures that diff --git a/django/contrib/gis/geos/geometries.py b/django/contrib/gis/geos/geometries.py index a185f5f3cb..47aa206687 100644 --- a/django/contrib/gis/geos/geometries.py +++ b/django/contrib/gis/geos/geometries.py @@ -7,7 +7,7 @@ from ctypes import c_uint, byref from types import FloatType, IntType, ListType, TupleType from django.contrib.gis.geos.base import GEOSGeometry from django.contrib.gis.geos.coordseq import GEOSCoordSeq -from django.contrib.gis.geos.error import GEOSException, GEOSGeometryIndexError +from django.contrib.gis.geos.error import GEOSException, GEOSIndexError from django.contrib.gis.geos.libgeos import get_pointer_arr, GEOM_PTR, HAS_NUMPY from django.contrib.gis.geos.prototypes import * if HAS_NUMPY: from numpy import ndarray, array @@ -328,7 +328,7 @@ class Polygon(GEOSGeometry): def _checkindex(self, index): "Internal routine for checking the given ring index." if index < 0 or index >= len(self): - raise GEOSGeometryIndexError('invalid Polygon ring index: %s' % index) + raise GEOSIndexError('invalid Polygon ring index: %s' % index) def get_interior_ring(self, ring_i): """ diff --git a/django/contrib/gis/geos/libgeos.py b/django/contrib/gis/geos/libgeos.py index 2268be0308..ed02357540 100644 --- a/django/contrib/gis/geos/libgeos.py +++ b/django/contrib/gis/geos/libgeos.py @@ -17,9 +17,18 @@ try: except ImportError: HAS_NUMPY = False +# Custom library path set? +try: + from django.conf import settings + lib_name = settings.GEOS_LIBRARY_PATH +except (AttributeError, EnvironmentError): + lib_name = None + # Setting the appropriate name for the GEOS-C library, depending on which # OS and POSIX platform we're running. -if os.name == 'nt': +if lib_name: + pass +elif os.name == 'nt': # Windows NT library lib_name = 'libgeos_c-1.dll' elif os.name == 'posix': diff --git a/django/contrib/gis/tests/test_geos.py b/django/contrib/gis/tests/test_geos.py index 2fe9113135..8a864e447f 100644 --- a/django/contrib/gis/tests/test_geos.py +++ b/django/contrib/gis/tests/test_geos.py @@ -1,7 +1,7 @@ import random, unittest, sys from ctypes import ArgumentError from django.contrib.gis.geos import \ - GEOSException, GEOSGeometryIndexError, \ + GEOSException, GEOSIndexError, \ GEOSGeometry, Point, LineString, LinearRing, Polygon, \ MultiPoint, MultiLineString, MultiPolygon, GeometryCollection, \ fromstr, geos_version, HAS_NUMPY @@ -144,7 +144,7 @@ class GEOSTest(unittest.TestCase): self.assertAlmostEqual(mp.centroid[0], mpnt.centroid.tuple[0], 9) self.assertAlmostEqual(mp.centroid[1], mpnt.centroid.tuple[1], 9) - self.assertRaises(GEOSGeometryIndexError, mpnt.__getitem__, len(mpnt)) + self.assertRaises(GEOSIndexError, mpnt.__getitem__, len(mpnt)) self.assertEqual(mp.centroid, mpnt.centroid.tuple) self.assertEqual(mp.points, tuple(m.tuple for m in mpnt)) for p in mpnt: @@ -169,7 +169,7 @@ class GEOSTest(unittest.TestCase): self.assertEqual(True, ls == fromstr(l.wkt)) self.assertEqual(False, ls == prev) - self.assertRaises(GEOSGeometryIndexError, ls.__getitem__, len(ls)) + self.assertRaises(GEOSIndexError, ls.__getitem__, len(ls)) prev = ls # Creating a LineString from a tuple, list, and numpy array @@ -199,7 +199,7 @@ class GEOSTest(unittest.TestCase): self.assertEqual(ls.geom_typeid, 1) self.assertEqual(ls.empty, False) - self.assertRaises(GEOSGeometryIndexError, ml.__getitem__, len(ml)) + self.assertRaises(GEOSIndexError, ml.__getitem__, len(ml)) self.assertEqual(ml.wkt, MultiLineString(*tuple(s.clone() for s in ml)).wkt) self.assertEqual(ml, MultiLineString(*tuple(LineString(s.tuple) for s in ml))) @@ -252,9 +252,9 @@ class GEOSTest(unittest.TestCase): self.assertEqual(p.ext_ring_cs, poly[0].tuple) # Testing __getitem__ # Testing __getitem__ and __setitem__ on invalid indices - self.assertRaises(GEOSGeometryIndexError, poly.__getitem__, len(poly)) - #self.assertRaises(GEOSGeometryIndexError, poly.__setitem__, len(poly), False) - self.assertRaises(GEOSGeometryIndexError, poly.__getitem__, -1) + self.assertRaises(GEOSIndexError, poly.__getitem__, len(poly)) + #self.assertRaises(GEOSIndexError, poly.__setitem__, len(poly), False) + self.assertRaises(GEOSIndexError, poly.__getitem__, -1) # Testing __iter__ for r in poly: @@ -283,7 +283,7 @@ class GEOSTest(unittest.TestCase): self.assertEqual(mp.num_geom, mpoly.num_geom) self.assertEqual(mp.n_p, mpoly.num_coords) self.assertEqual(mp.num_geom, len(mpoly)) - self.assertRaises(GEOSGeometryIndexError, mpoly.__getitem__, len(mpoly)) + self.assertRaises(GEOSIndexError, mpoly.__getitem__, len(mpoly)) for p in mpoly: self.assertEqual(p.geom_type, 'Polygon') self.assertEqual(p.geom_typeid, 3) @@ -618,15 +618,15 @@ class GEOSTest(unittest.TestCase): # Testing __getitem__ (doesn't work on Point or Polygon) if isinstance(g, Point): - self.assertRaises(GEOSGeometryIndexError, g.get_x) + self.assertRaises(GEOSIndexError, g.get_x) elif isinstance(g, Polygon): lr = g.shell self.assertEqual('LINEARRING EMPTY', lr.wkt) self.assertEqual(0, len(lr)) self.assertEqual(True, lr.empty) - self.assertRaises(GEOSGeometryIndexError, lr.__getitem__, 0) + self.assertRaises(GEOSIndexError, lr.__getitem__, 0) else: - self.assertRaises(GEOSGeometryIndexError, g.__getitem__, 0) + self.assertRaises(GEOSIndexError, g.__getitem__, 0) def test21_test_gdal(self): "Testing `ogr` and `srs` properties."