HOW TO

Remove cross-edged polygons using ArcPy in ArcGIS Pro

First Published: May 20, 2026
Last Published: May 20, 2026

Summary

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.

Procedure

  1. In ArcGIS Pro, on the View ribbon tab, in the Windows group, click Python Window.
  2. In the Python window, copy and paste the code below to remove the cross-edged polygons using ArcPy.
    1. Import the ArcPy library and Python's itertools module.
from itertools import combinations
import arcpy
  1. Define the feature layer.
polygon_fc = "TEST_POLYGONS"
  1. Create a copy of the feature layer.
arcpy.management.CopyFeatures(polygon_fc, "edited_polygon")
  1. Initialize counters.
overlap_count = 0           
edited_polygon_count = 0   
  1. Retrieve object IDs and polygon geometries.
polygon_dict = {
    row[0]: row[1]
    for row in arcpy.da.SearchCursor("edited_polygon", ["OID@", "SHAPE@"])
}
  1. Perform pairwise comparisons of the polygons from the feature layer.
for oid1, oid2 in combinations(polygon_dict, 2):
    polygon1 = polygon_dict[oid1]
    polygon2 = polygon_dict[oid2]
  1. Check for polygons with no intersection.
if polygon1.disjoint(polygon2):
        continue
  1. Check for polygon containments.
if polygon1.contains(polygon2) or polygon1.within(polygon2):
        continue
  1. Identify cross-edged areas.
intersect_polygon = polygon1.intersect(polygon2, 4)
    if intersect_polygon.getArea() <= 0:
        continue

    overlap_count += 1
  1. Remove the cross-edged areas 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
  1. Display the output message.
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)
  1. Press Enter twice to execute the Python code.

The output message below summarize the number of cross-edged areas removed and the number of polygons updated.

The output message

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

The polygon without the cross-edged area

Article ID: 000041290

Software:
  • ArcGIS Pro

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options