1

By Running this piece of code:

import arcpy
arcpy.env.workspace = "C:\working\GEODATABASES\\tests.gdb"
fcList = arcpy.ListFeatureClasses()
for fc in fcList:
    with arcpy.da.SearchCursor(fc, ("OID@", "SHAPE@")) as cursor:
    for row in cursor:
        print("Feature {0}".format(row[0]))
        print "   " + str(row[1].partCount) + " parts for THIS PARTICULAR FEATURE"
        for part in row[1]:
            poly = arcpy.Polygon(part)
            print("   Points {0}".format(poly.pointCount))  

In theory I am able to list all polygons for a particular feature class and list whether they are multi-part polygons or not. In addition, it shows the number of points per feature part.

HOWEVER, it does not do the job properly as I am dealing with a complicate feature class that actually have more feature parts than the script can identify. Even in some of them, it does not obtain the right number of points per part either.

By using the OLD reading cursor system in arcpy (not the above one), I get in some polygons a different number of points, but still there are some of them missing, therefore the script cannot access to them.

Why is that this script stops counting either points or parts sometimes when entering a multipart-polygon within my feature class?

Is it my code not well tuned for complicated multi-part polygons?

Thanks,

  • How did you create polygons with zero-point parts? Since having fewer than four vertices (three unique, and the first one repeated to close the part) is invalid, maybe you should add some exception handling to your code. – Vince May 30 '14 at 12:35
  • Exactly, this is why my code cannot read those parts. arcpy.Polygon is ONLY working with 'ideal' or 'cleaned' parts in which no complicated topologies are found. The feature class was created by digitizing, does not matter, but you can visualize these 'NULL' or 'invalid' parts in ArcMap as they appear as straight lines or segments crossing each other. I am not sure about including an exception to identify wrong geometries as arcpy.Polygon is unable to trace them. – Web-GIS entrepreneur May 30 '14 at 12:43
  • I mean, why the code skip some parts? – Web-GIS entrepreneur May 30 '14 at 12:54
  • 1
    If you just need to repair a feature class with broken geometry, Repair Geometry is your choice; however, I'd backup the data first as the tool is not omnipotent. – Jan Šimbera Jun 2 '14 at 13:08
  • Does the repair tool tell you where the wrong geometries are? because this is what I need and this is why I built the script – Web-GIS entrepreneur Jun 3 '14 at 8:05
2

Have you tried using the old-style SearchCursor (not the one from the da module)? It may not be as efficient, but I think it is much more bugproof. I would also replace the line

poly = arcpy.Polygon(part)

by checking the length of the part.

  • How do you calculate the length or the number of vertices without creating a polygon layer first? – Web-GIS entrepreneur May 30 '14 at 14:41
  • The polygon layer is the input; arcpy.Polygon only creates a single object from a sequence of points, which is not necessary as you can just check the length of the sequence. – Jan Šimbera Jun 2 '14 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.