[gdal-dev] vertex counts in ogr

Cody Schank codyschank at gmail.com
Wed Jun 20 14:04:39 PDT 2012


Hi,

I just started using ogr a couple of weeks ago, as I move away from arcpy.

After some head scratching, I came up with the following code to get a
vertex count for a polygon shapefile:

numVertices = 0
dataSource = driver.Open(shp, 0)
layer = dataSource.GetLayer()
for feature in layer:
     geom = feature.GetGeometryRef()
     for polygon in geom:
          numVertices += polygon.GetPointCount()

The script works, but returns a different count from the script I have used
in the past with arcpy (pasted below)

numVertices = 0
desc = arcpy.Describe(shp)
shapefieldname = desc.ShapeFieldName
rows = arcpy.SearchCursor(shp)
for row in rows:
     feat = row.getValue(shapefieldname)
     numVertices += feat.pointCount


Any help would be awesome!

Thanks!
Cody
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20120620/c11dcb1d/attachment.html>


More information about the gdal-dev mailing list