how do i clear duplicate entities created in feature classes

4435
3
04-16-2015 01:00 AM
TanmayNaik
New Contributor

how do i clear duplicate entities created while copying data in feature classes assuming the duplicates are at same XYZ locations as the original data, i am working on Point and Line data, is there any inbuilt tool in Arc Gis which i can use for the same?Can anyone help me with a python script here for the purpose.how do i clear duplicate entities created while copying data in feature classes assuming the duplicates are at same XYZ locations as the original data, i am working on Point and Line data, is there any inbuilt tool in Arc Gis which i can use for the same?Can anyone help me with a python script here for the purpose.Thanks

0 Kudos
3 Replies
KishorGhatage
Occasional Contributor III

Find Identical (Data Management)

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

Delete Identical (Data Management)

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

GerryGabrisch
Occasional Contributor III

Here is an updated version of my Find and Delete Spatially Duplicate Records in a Shapefile.  This code works in ArcGIS 10.1+ and does not require and advance license, it works on any feature class, and it runs much faster relying on geometry and not selections.

The geometry compare only uses X and y and not z values, sorry but the method comes that way from ESRI.  There is no consideration of the attribute table but the tool preserves the original FC.

try:
    print "Find And Delete Spatially Duplicate Records in a Feature Class..."
    print "A Two-Bit Algorithms product\nby Gerry Gabrisch (geraldg@lummi-nsn.gov)"
    print "Copy?Right! 2015...Free to hack with with attribution."
    
    import sys, traceback, time
    import arcpy
    from arcpy import env
    
    env.overwriteOutput = True


    #the input FC with duplicate records....
    inFC= r"C:\gTemp\Converted_Graphics.shp"
    #The output FC that will have duplicate records purged....
    outFC = r"C:\gTemp\Converted_GraphicsTEST.shp"
    
    arcpy.CopyFeatures_management(inFC, outFC)

    
    with arcpy.da.SearchCursor(inFC, ["OID@", "SHAPE@"]) as cursor:
        for row in cursor:
            with arcpy.da.UpdateCursor(outFC, ["OID@", "SHAPE@"]) as cursor2:
                dupcount = 0
                for row2 in cursor2:
                    if cursor[1].equals(cursor2[1]):
                        dupcount +=1
                        if dupcount >=2:
                            dupcount = 1
                            cursor2.deleteRow()

    
except arcpy.ExecuteError: 
    print "error"
    msgs = arcpy.GetMessages(2) 
    arcpy.AddError(msgs)  
    print msgs
except:
    print "error"
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
    print pymsg + "\n"