03-27-2020 07:48 AM
New Contributor III
# Name:
# Description: Delete identical features in a dataset based on Shape (geometry) and a TEXT field.
# Import system modules
import arcpy
arcpy.env.overwriteOutput = True
# Set workspace environment
arcpy.env.workspace = "C:/data/sbfire.gdb"
# Set input feature class
in_dataset = "fireincidents"
# Set the field upon which the identicals are found
fields = ["Shape", "INTENSITY"]
# Set the XY tolerance within which to identical records to be deleted
xy_tol = "0.02 Miles"
# Set the Z tolerance to default
z_tol = ""
# Execute Delete Identical
arcpy.DeleteIdentical_management(in_dataset, fields, xy_tol, z_tol)

I just want to clarify which order it selects the objects to delete?

Thanks in advance~~~~

0 Kudos
4 Replies
MVP Esteemed Contributor

Pretty sure in order of the ObjectID; so the feature with the greatest OID value remains.  But don't take my word for it; try your script on a couple of identical test features to be sure..

0 Kudos
MVP Esteemed Contributor

Esri doesn't disclose their exact methodology. In all likelihood, ObjectID/FID is probably used to sort the data set so the lowest OID/FID will be kept and higher marked for deletion.  That said, I would not depend on that behavior since it isn't documented, even if it does appear to work that way.  The documentation does state that Find Identical—Data Management toolbox | Documentation uses the same methodology, whatever that may be, so you can use Find Identical to see what the results would be from running Delete Identical.  

MVP Regular Contributor

You could do this with a search cursor.

1. Create a dictionary of OID keys and values of [SHAPE@, Intensity, Field]

2.Iterate through each OID to find matching SHAPE@ and Intensity and append them to a list. should have a list of all OIDs classed as identical by position and Intensity.

Iterate through that list using the initial dictionary to find where field is N or Y

MVP Esteemed Contributor

True, rolling your own is always an option, and maybe the only option here for the OP.

0 Kudos