1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

gis: gdal: GeometryCollection.add() now accepts other collections, and associated tests.

git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7012 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2008-01-09 19:42:23 +00:00
parent 298074d5b8
commit 5655cf1b2a
2 changed files with 26 additions and 3 deletions

View File

@ -538,13 +538,15 @@ class GeometryCollection(OGRGeometry):
def add(self, geom):
"Add the geometry to this Geometry Collection."
if isinstance(geom, OGRGeometry):
ptr = geom._ptr
if isinstance(geom, self.__class__):
for g in geom: add_geom(self._ptr, g._ptr)
else:
add_geom(self._ptr, geom._ptr)
elif isinstance(geom, (StringType, UnicodeType)):
tmp = OGRGeometry(geom)
ptr = tmp._ptr
add_geom(self._ptr, tmp._ptr)
else:
raise OGRException('Must add an OGRGeometry.')
add_geom(self._ptr, ptr)
@property
def point_count(self):

View File

@ -323,6 +323,27 @@ class OGRGeomTest(unittest.TestCase):
a |= b # testing __ior__
self.assertEqual(u1, a)
def test14_add(self):
"Testing GeometryCollection.add()."
# Can't insert a Point into a MultiPolygon.
mp = OGRGeometry('MultiPolygon')
pnt = OGRGeometry('POINT(5 23)')
self.assertRaises(OGRException, mp.add, pnt)
# GeometryCollection.add may take an OGRGeometry (if another collection
# of the same type all child geoms will be added individually) or WKT.
for mp in multipolygons:
mpoly = OGRGeometry(mp.wkt)
mp1 = OGRGeometry('MultiPolygon')
mp2 = OGRGeometry('MultiPolygon')
mp3 = OGRGeometry('MultiPolygon')
for poly in mpoly:
mp1.add(poly) # Adding a geometry at a time
mp2.add(poly.wkt) # Adding WKT
mp3.add(mpoly) # Adding a MultiPolygon's entire contents at once.
for tmp in (mp1, mp2, mp3): self.assertEqual(mpoly, tmp)
def suite():
s = unittest.TestSuite()
s.addTest(unittest.makeSuite(OGRGeomTest))