On 02/09/2011 05:36 PM, Frank Broniewski wrote:
Yes, thank you. GetPointCount() works. Another thing I noticed:

point = geometry.GetPoint(point_index)

point is of type tuple(x, y, z), not as one would guess an OGRPoint() geometry. At least for me this was unexpected. And the python GetPoint method does not take a OGRPoint geometry, like it is mentioned here [1]

The OGC name of GetPoint is PointN and it should return a Point object according to the standard.

The GDAL Perl (which I care for) works the same way, GetPoint returns a list of coordinates. It would be possible to make it return a geometry object in scalar context, but I'm not sure if Python has that possibility.

The GDAL Perl documentation for Geometry object is at http://geoinformatics.tkk.fi/doc/Geo-GDAL/html/class_geo_1_1_o_g_r_1_1_geometry.html I'm not aware of GDAL Python documentation in the web. There are differences between GDAL C++ API and GDAL C API. For the bindings the C API documentation is usually better: http://www.gdal.org/ogr/ogr__api_8h.html#67b897ffcd88a83832964c3735fa1dcb

Best regards,

Ari


Frank


[1] http://www.gdal.org/ogr/classOGRLineString.html#ab63760022e49a795477f2fd31da059f

Am 09.02.2011 15:44, schrieb Ari Jolma:
On 02/09/2011 04:19 PM, Frank Broniewski wrote:
Hi,

just a quick question: isn't GetNumPoints implemented on a geometry in
ogr python?

There are OGR_G_GetPointCount in ogr_api.h and GetPointCount method in
the Geometry class in Swig bindings.

Hm. It seems that NumPoints is the name of the method in the OGC simple
features standard (it is defined for LineStrings).

Ari

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


_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev




_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to