[gdal-dev] [python-ogr] GetNumPoints from geometry

Frank Broniewski brfr at metrico.lu
Wed Feb 9 09:19:52 EST 2011


Hi,

just a quick question: isn't GetNumPoints implemented on a geometry in 
ogr python? Neither GetNumPoints() nor getNumPoints() (small g) work.
The passed in geometry is a geometry object from a

geometry = feature.GetGeometryRef()

call and the geometry is of type 'LINESTRING' taken from

geometry.GetGeometryName() ...


code:
def line_nodes(geometry):
     nodes = list()

     for point_index in xrange(geometry.GetNumPoints()):
         ogr_point = ogr.OGRPoint()
         point = geometry.GetPoint(point_index, ogr_point)
         dimenion = point.GetCoordinateDimension()
         if dimension == 3:
             list.append(point_index, point.GetX(), point.GetY(), 
point.GetZ())
         else:
             list.append(point_index, point.GetX(), point.GetY())

     return nodes


raises an AttributeError
...
     for point_index in xrange(geometry.getNumPoints()):
   File "C:\Python26\lib\site-packages\osgeo\ogr.py", line 2672, in <lambda>
     __getattr__ = lambda self, name: _swig_getattr(self, Geometry, name)
   File "C:\Python26\lib\site-packages\osgeo\ogr.py", line 34, in 
_swig_getattr
     raise AttributeError,name
AttributeError: GetNumPoints


Many thanks

Frank

-- 
Frank BRONIEWSKI

METRICO s.à r.l.
géomètres
technologies d'information géographique
rue des Romains 36
L-5433 NIEDERDONVEN

tél.: +352 26 74 94 - 28
fax.: +352 26 74 94 99
http://www.metrico.lu


More information about the gdal-dev mailing list