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)
advanced license required
And from @JoshuaBixby
You can examine his gist code.