HOW TO
In ArcGIS Pro, ArcPy can be used to selectively remove cross-edged polygons while preserving the remaining polygon geometry. Using ArcPy avoids unintended removal of polygon areas.
from itertools import combinations import arcpy
polygon_fc = "TEST_POLYGONS"
arcpy.management.CopyFeatures(polygon_fc, "edited_polygon")
overlap_count = 0 edited_polygon_count = 0
polygon_dict = {
row[0]: row[1]
for row in arcpy.da.SearchCursor("edited_polygon", ["OID@", "SHAPE@"])
}
for oid1, oid2 in combinations(polygon_dict, 2):
polygon1 = polygon_dict[oid1]
polygon2 = polygon_dict[oid2]
if polygon1.disjoint(polygon2):
continue
if polygon1.contains(polygon2) or polygon1.within(polygon2):
continue
intersect_polygon = polygon1.intersect(polygon2, 4)
if intersect_polygon.getArea() <= 0:
continue
overlap_count += 1
if polygon1.getArea() > polygon2.getArea():
with arcpy.da.UpdateCursor(
"edited_polygon", ["SHAPE@"], f"OBJECTID = {oid2}"
) as cursor:
for row in cursor:
row[0] = polygon2.difference(polygon1)
cursor.updateRow(row)
edited_polygon_count += 1
else:
with arcpy.da.UpdateCursor(
"edited_polygon", ["SHAPE@"], f"OBJECTID = {oid1}"
) as cursor:
for row in cursor:
row[0] = polygon1.difference(polygon2)
cursor.updateRow(row)
edited_polygon_count += 1
if overlap_count > 0:
msg = (
f"Success: {overlap_count} cross-edged area successfully removed. "
f"{edited_polygon_count} polygon geometry updated."
)
arcpy.AddMessage(msg)
print(msg)
else:
msg = "No cross-edged polygons were detected. No polygon geometry was modified."
arcpy.AddWarning(msg)
print(msg)
The following code shows the full sample script.
from itertools import combinations
import arcpy
# define input polygon layer (must exist in the map)
polygon_fc = "TEST_POLYGONS"
# Create a copy of the feature layer
arcpy.management.CopyFeatures(polygon_fc, "edited_polygon")
# Initialize counters
overlap_count = 0 # number of cross-edged AREAS
edited_polygon_count = 0 # number of polygon geometries edited
# Get a dictionary of OIDs and geometries
polygon_dict = {
row[0]: row[1]
for row in arcpy.da.SearchCursor("edited_polygon", ["OID@", "SHAPE@"])
}
# pairwise compare all polygons
for oid1, oid2 in combinations(polygon_dict, 2):
polygon1 = polygon_dict[oid1]
polygon2 = polygon_dict[oid2]
# skip if polygons are completely disjoint
if polygon1.disjoint(polygon2):
continue
# skip if containment exists (polygon fully within another polygon)
if polygon1.contains(polygon2) or polygon1.within(polygon2):
continue
# get intersecting geometry (cross-edge overlap candidate)
intersect_polygon = polygon1.intersect(polygon2, 4)
if intersect_polygon.getArea() <= 0:
continue
# a cross-edged area is detected
overlap_count += 1
# remove overlap area from the polygon
if polygon1.getArea() > polygon2.getArea():
with arcpy.da.UpdateCursor(
"edited_polygon", ["SHAPE@"], f"OBJECTID = {oid2}"
) as cursor:
for row in cursor:
row[0] = polygon2.difference(polygon1)
cursor.updateRow(row)
edited_polygon_count += 1
else:
with arcpy.da.UpdateCursor(
"edited_polygon", ["SHAPE@"], f"OBJECTID = {oid1}"
) as cursor:
for row in cursor:
row[0] = polygon1.difference(polygon2)
cursor.updateRow(row)
edited_polygon_count += 1
# Executed when one or more cross-edged areas are detected and removed
if overlap_count > 0:
msg = (
f"Success: {overlap_count} cross-edged area successfully removed. "
f"{edited_polygon_count} polygon geometry updated."
)
arcpy.AddMessage(msg)
print(msg)
else:
msg = "No cross-edged polygons were detected. No polygon geometry was modified."
arcpy.AddWarning(msg)
print(msg)
The output message below summarize the number of cross-edged areas removed and the number of polygons updated.

The map below displays the middle polygon with two cross-edged areas from other polygons removed.

Article ID: 000041290
Get help from ArcGIS experts
Start chatting now