Changeset 904

Show
Ignore:
Timestamp:
10/13/07 09:28:11
Author:
seang
Message:

Provide geo interface for points, linestrings, and linearrings (#125)

Files:

Legend:

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

    r548 r904  
    280280    z = property(getZ, setZ) 
    281281 
     282    def _provideGeoInterface(self): 
     283        return { 
     284            'type': 'Point', 
     285            'coordinates': (self.x, self.y, self.z) 
     286            } 
     287    __geo_interface__ = property(_provideGeoInterface) 
     288 
    282289 
    283290class LineString(Geometry): 
     
    340347        return self.startPoint().equals(self.endPoint()) 
    341348 
     349    def _provideGeoInterface(self): 
     350        coords = [] 
     351        for i in range(self.numPoints()): 
     352            p = self.pointN(i) 
     353            coords.append((p.x, p.y, p.z)) 
     354        return { 
     355            'type': 'LineString', 
     356            'coordinates': tuple(coords)  
     357            } 
     358    __geo_interface__ = property(_provideGeoInterface) 
     359 
    342360 
    343361class LinearRing(LineString): 
     
    370388            self._copyFromCoordSeq(s, GEOS_LINEARRING) 
    371389 
     390    def _provideGeoInterface(self): 
     391        coords = [] 
     392        for i in range(self.numPoints()): 
     393            p = self.pointN(i) 
     394            coords.append((p.x, p.y, p.z)) 
     395        return { 
     396            'type': 'LinearRing', 
     397            'coordinates': tuple(coords)  
     398            } 
     399    __geo_interface__ = property(_provideGeoInterface) 
     400 
    372401       
    373402class Polygon(Geometry): 
     
    409438        """Return a point on surface.""" 
    410439        return self._unary_geometry_operation('getInteriorRingN', N) 
    411      
     440 
     441    #def _provideGeoInterface(self): 
     442    #    coords = [] 
     443    #    for i in range(self.numPoints()): 
     444    #        p = self.pointN(i) 
     445    #        coords.append((p.x, p.y, p.z)) 
     446    #    return { 
     447    #        'type': 'LineString', 
     448    #        'coordinates': tuple(coords)  
     449    #        } 
     450    #__geo_interface__ = property(_provideGeoInterface) 
     451 
    412452 
    413453class GeometryCollection(Geometry):