1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

gis: renamed GEOSGeometryIndexError to GEOSIndexError; added GEOS_LIBRARY_PATH settings option.

git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@6861 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2007-12-03 06:27:16 +00:00
parent 23384af79b
commit facc725d21
8 changed files with 30 additions and 44 deletions

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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."

View File

@ -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

View File

@ -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):
"""

View File

@ -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':

View File

@ -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."