Changeset 906

Show
Ignore:
Timestamp:
10/13/07 10:41:40
Author:
seang
Message:

Provide geo interface from multipoints, multilines, and multipolygons (#125)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PCL/trunk/PCL-Core/cartography/geometry/geometry.py

    r905 r906  
    500500            x = createCollection(GEOS_MULTIPOINT, points) 
    501501            self._copyFromGeom(x) 
    502    
     502 
     503    def _provideGeoInterface(self): 
     504        coords = [] 
     505        for i in range(self.numGeometries()): 
     506            p = self.geometryN(i) 
     507            coords.append((p.x, p.y, p.z)) 
     508        return { 
     509            'type': 'MultiPoint', 
     510            'coordinates': tuple(coords)  
     511            } 
     512    __geo_interface__ = property(_provideGeoInterface) 
     513 
    503514 
    504515class MultiLineString(GeometryCollection): 
     
    526537            self._copyFromGeom(x) 
    527538 
     539    def _provideGeoInterface(self): 
     540        allcoords = [] 
     541        for i in range(self.numGeometries()): 
     542            line = self.geometryN(i) 
     543            coords = [] 
     544            for j in range(line.numPoints()): 
     545                p = line.pointN(j) 
     546                coords.append((p.x, p.y, p.z)) 
     547            allcoords.append(tuple(coords)) 
     548        return { 
     549            'type': 'MultiLineString', 
     550            'coordinates': tuple(allcoords)  
     551            } 
     552    __geo_interface__ = property(_provideGeoInterface) 
     553 
    528554 
    529555class MultiPolygon(GeometryCollection): 
     
    550576            x = createCollection(GEOS_MULTIPOLYGON, polygons) 
    551577            self._copyFromGeom(x) 
     578 
     579    def _provideGeoInterface(self): 
     580        allcoords = [] 
     581        for i in range(self.numGeometries()): 
     582            g = self.geometryN(i) 
     583            geomcoords = [] 
     584            exring = g.exteriorRing() 
     585            ringcoords = [] 
     586            for k in range(exring.numPoints()): 
     587                p = exring.pointN(k) 
     588                ringcoords.append((p.x, p.y, p.z)) 
     589            geomcoords = [tuple(ringcoords)] 
     590            for j in range(g.numInteriorRings()): 
     591                inring = g.interiorRingN(j) 
     592                ringcoords = [] 
     593                for k in range(inring.numPoints()): 
     594                    p = inring.pointN(k) 
     595                    ringcoords.append((p.x, p.y, p.z)) 
     596                geomcoords.append(tuple(ringcoords)) 
     597            allcoords.append(tuple(geomcoords)) 
     598        return { 
     599            'type': 'MultiPolygon', 
     600            'coordinates': tuple(allcoords)  
     601            } 
     602    __geo_interface__ = property(_provideGeoInterface) 
    552603 
    553604