I have a number of features which I would like to individually Union with itself to remove internal gaps. The best way I've thought of so far is to use cursors and iterate through, essentially performing the Union as many times as I have rows in my feature class.
Is there a tool or other approach that might be more efficient?
Note I do not want to Union everything in the feature class together - the individual results should stay separate and should have as many rows output as I originally input.
I'd like to perform this in one of Esri's products/ArcPy (ArcGIS Pro preferred over ArcMap).
Per @Keagan Allan I tried the dissolve tool but wound up with the same polygon - the interior gap was not removed. A polygon example is below. (Note the view is filtered to only show this polygon - see second image.)
The second image shows that the polygon is overlapping several other polygons which need to be kept separate (and if they have gaps, those gaps should be removed as well.)
UPDATE: The "Eliminate Polygon Part" (Advanced license) tool worked. I don't know whether something similar to this tool is available in other license levels or open source GIS, as replicability is a concern. (It may be better to use the repeated union for that reason.)
arcpy.management.EliminatePolygonPart("input_layer", "output_layer_eliminate", "PERCENT", "0 SquareMeters", 99, "CONTAINED_ONLY")
UPDATE2: I tried @FelixIP's method in arcpy (Python 2.7) and see a change in the outer border but it's no longer following the line. In the below screenshot, the greenish line is the resulting polygon from the code below, and the cyan is the original polygon.
I did the "check for gaps" and "remove gaps" separately because I wanted to examine the results of the first operation before proceeding, but theoretically could combine the two.
# Identify whether a polygon has an interior gap
with arcpy.da.UpdateCursor("infc", ["uniqueid", "SHAPE@", "HasInnerRing"]) as cur:
for row in cur:
print(row[0])
for part in row[1]:
partlist = [pnt for pnt in part]
#print(partlist)
if None in partlist:
print("{} has inner ring".format(row[0]))
row[2] = 1
else:
row[2] = 0
cur.updateRow(row)
# Remove gaps, if they have been identified in previous step
with arcpy.da.UpdateCursor("infc", ["uniqueid", "SHAPE@", "HasInnerRing"]) as cur:
for row in cur:
if row[2] == 1:
part = row[1].getPart(0)
pgon = arcpy.Polygon(part)
row[1] = pgon
cur.updateRow(row)