I've written a script that should remove holes from polygons with use of cursors and geometry objects. However, holes remain even though I'm constructing new polygons from the vertices from the first part of the input polygon geometry.
Here's the script:
def RemoveHoles (inFc, workspace): outFc = UniqueFileName(workspace) #creates a file path/name string array = arcpy.Array () sr = arcpy.Describe (inFc).spatialReference outPath, outName = os.path.split (outFc) arcpy.CreateFeatureclass_management (outPath, outName, "POLYGON", spatial_reference = sr) with arcpy.da.InsertCursor (outFc, "SHAPE@") as iCurs: with arcpy.da.SearchCursor (inFc, "SHAPE@") as sCurs: for geom, in sCurs: for i in range (geom.partCount): part = geom.getPart (i) for pnt in part: print pnt if not pnt: break array.add (geom.getPart (0)) print array.count polygon = arcpy.Polygon (array) array.removeAll () row = (polygon,) iCurs.insertRow (row) del iCurs del sCurs return outFc
For this polygon:
The output reads as so:
571048.0859 4230953.3243 NaN NaN 571762.4623 4225079.5626 NaN NaN 566206.2012 4227698.9428 NaN NaN 571048.0859 4230953.3243 NaN NaN None 4
And yet, despite the fact that I'm constructing a new polygon from three points, the hole is still preserved in the output feature class. Does anyone have any idea why?