How to delete parts from geometry object?

73
1
05-11-2021 03:36 AM
ThomasBecker1
Occasional Contributor II

I have a FeatureClass of polygons. A good part of those polygons have holes and I would like to get rid of them if they are below a certain size.

I managed to get to the parts and calculate their size. I also thought I delete unwanted parts... however, when writing them out there is no difference. I do not really know if my error is located in the part of deleting parts or at the point where I try to write them to disk.

 

 

arcpy.management.CreateFeatureclass(fc_path, 'clear', 'POLYGON', spatial_reference=sr)
geoms = arcpy.management.CopyFeatures(simplified, arcpy.Geometry())

with arcpy.da.InsertCursor(without_holes, 'SHAPE@') as iCursor:
    for geom in geoms:
        partnum = geom.partCount
        parts = geom.getPart()
        if partnum > 1:
            lst_rm = []
            for n in range(1, partnum):
                part = geom.getPart(n)
                part_geom = arcpy.Polygon(part, sr)
                if part_geom.area > 50.0:
                    lst_rm.append(n)
            lst_rm.sort(reverse=True)
            for i in lst_rm:
                parts.remove(i)
        polygon = arcpy.Polygon(parts)
        row = (polygon,)
        iCursor.insertRow(row)

 

0 Kudos
1 Reply
DanPatterson
MVP Honored Contributor

advanced license required

Eliminate Polygon Part (Data Management)—ArcGIS Pro | Documentation

And from @JoshuaBixby 

ArcPy: Remove Holes in Polygons (github.com)

You can examine his gist code.


... sort of retired...