Select to view content in your preferred language

Finding Duplicate lines or lines that intersect.

7940
11
08-06-2012 07:49 AM
JayKappy
Frequent Contributor
I have a single Feature Class of Pipes....I noticed that somehow along the way Duplicates were created.
They are basically exact duplicates right on top of one another.

Is there a tool to run to find the lines that intersect or duplicate in a single Feature Class?

THanks
Tags (2)
0 Kudos
11 Replies
NobbirAhmed
Esri Regular Contributor
Hi Jason,

Try this code. Set the path of your input data to in_fc. I haven't done anything (other than printing) with the duplicate features - you'll need to use either an insertcursor (with a new empty feature class) or updatecursor (to work with current feature class) to carry over the unique features.

import arcpy

in_fc = r"C:\mytools\findidentical\geom_equals.gdb\trailsfew"

dsc = arcpy.Describe(in_fc)
sr = dsc.spatialReference
oid_field_name = dsc.oidFieldName

# get a cursor on the input features
rows1 = arcpy.SearchCursor(in_fc)

# exclude features already compared once
exclude = []

# iterate through the first coursor
for row1 in rows1:
    
    oid1 = row1.getValue(oid_field_name)
    shp1 = row1.shape
    
    # get a second cursor on the same input features
    rows2 = arcpy.SearchCursor(in_fc)
    
    # add the feature to be compared to exclude list
    exclude.append(oid1)
    
    # create a set to hold duplicate features
    group = set()
    
    # iterate through the second cursor
    for row2 in rows2:
        
        oid2 = row2.getValue(oid_field_name)
        shp2 = row2.shape
        
        # ignore features already compared
        if oid2 in exclude:
            continue
        
        # test equality
        if shp1.equals(shp2):
            
            # add both feature ids to the set of identical features
            group.add(oid1)
            group.add(oid2)
            
            # add the feature just compared to the exclude list
            exclude.append(oid2)
            
    if group:  # if the group is not empty
        print group


Note: I have used two separate cursors on the same feature class. This is due to some issues at 10.0 - at 10.1 one cursor is enough.

Let me know if you find any issue or if you need help with creating an output.

Thanks, Nobbir
0 Kudos
JasonKleps
Emerging Contributor
Hi Jason,

Try this code. Set the path of your input data to in_fc. I haven't done anything (other than printing) with the duplicate features - you'll need to use either an insertcursor (with a new empty feature class) or updatecursor (to work with current feature class) to carry over the unique features.

Note: I have used two separate cursors on the same feature class. This is due to some issues at 10.0 - at 10.1 one cursor is enough.

Let me know if you find any issue or if you need help with creating an output.

Thanks, Nobbir


Thanks Nobbir - This is a great Christmas present!

- Jason.
0 Kudos