Find overlapping features

In ArcGIS 10, additional functions for performing relational operations was added to the geometry object. The following code uses the overlaps function to find overlapping features and prints out the ObjectID pairs. For a complete list of relational operators, see the Geometry class.

This code is supported in ArcGIS 10.0.

def find_overlaps(input_features):
    '''Find and print OID value pairs for overlapping features.'''
    oid_field = arcpy.ListFields(input_features, '*', 'OID')[0]
    for row in arcpy.SearchCursor(input_features, '', '', 'Shape;{0}'.format(oid_field.name)):
        for row2 in arcpy.SearchCursor(input_features, '', '', 'Shape;{0}'.format(oid_field.name)):
            if row2.Shape.overlaps(row.Shape):
                print '{0} overlaps {1}'.format(str(row2.getValue(oid_field.name)), str(row.getValue(oid_field.name)))

ArcGIS 10.1 introduces a new data access module, arcpy.da, for working with data. It includes cursor functions which provide improved cursor support and faster performance. The following code can replace the previous sample code and provide improved performance.

From more information about arcpy.da, see the data access module.

def find_overlaps(input_features):                
    '''Find and print OID value pairs for overlapping features.'''
    for row in arcpy.da.SearchCursor(input_features, ('OID@', 'SHAPE@')):
        for row2 in arcpy.da.SearchCursor(input_features, ('OID@', 'SHAPE@')):
            if row2[1].overlaps(row[1]):
                print '{0} overlaps {1}'.format(str(row2[0]), str(row[0]))

One thought on “Find overlapping features

  1. For an even faster approach at 10.1, use the itertools module and the combinations function. This code shows how to find overlaps without needing multiple cursors, and no repeat values are returned for each combination:

    with arcpy.da.SearchCursor(in_features, [‘OID@’, ‘SHAPE@’]) as cur:
    for e1,e2 in itertools.combinations(cur, 2):
    if e1[1].overlaps(e2[1]):
    print “{} overlaps {}”.format(e1[0],e2[0])

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s