Django

Code

Changeset 7012

Show
Ignore:
Timestamp:
01/09/08 13:42:23 (6 months ago)
Author:
jbronn
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/gdal/geometries.py

    r6862 r7012  
    539539        "Add the geometry to this Geometry Collection." 
    540540        if isinstance(geom, OGRGeometry): 
    541             ptr = geom._ptr 
     541            if isinstance(geom, self.__class__): 
     542                for g in geom: add_geom(self._ptr, g._ptr) 
     543            else: 
     544                add_geom(self._ptr, geom._ptr) 
    542545        elif isinstance(geom, (StringType, UnicodeType)): 
    543546            tmp = OGRGeometry(geom) 
    544             ptr = tmp._ptr 
     547            add_geom(self._ptr, tmp._ptr) 
    545548        else: 
    546549            raise OGRException('Must add an OGRGeometry.') 
    547         add_geom(self._ptr, ptr) 
    548550 
    549551    @property 
  • django/branches/gis/django/contrib/gis/tests/test_gdal_geom.py

    r6979 r7012  
    324324            self.assertEqual(u1, a) 
    325325 
     326    def test14_add(self): 
     327        "Testing GeometryCollection.add()." 
     328        # Can't insert a Point into a MultiPolygon. 
     329        mp = OGRGeometry('MultiPolygon') 
     330        pnt = OGRGeometry('POINT(5 23)') 
     331        self.assertRaises(OGRException, mp.add, pnt) 
     332 
     333        # GeometryCollection.add may take an OGRGeometry (if another collection 
     334        # of the same type all child geoms will be added individually) or WKT. 
     335        for mp in multipolygons: 
     336            mpoly = OGRGeometry(mp.wkt) 
     337            mp1 = OGRGeometry('MultiPolygon') 
     338            mp2 = OGRGeometry('MultiPolygon') 
     339            mp3 = OGRGeometry('MultiPolygon') 
     340 
     341            for poly in mpoly: 
     342                mp1.add(poly) # Adding a geometry at a time 
     343                mp2.add(poly.wkt) # Adding WKT 
     344            mp3.add(mpoly) # Adding a MultiPolygon's entire contents at once. 
     345            for tmp in (mp1, mp2, mp3): self.assertEqual(mpoly, tmp) 
     346 
    326347def suite(): 
    327348    s = unittest.TestSuite()