I try to use this python code in order to delete duplicated feature which as the same xy coordinate of centroid (i created those fields with Calculated Geometry in the attribute table):
import arcpy
'''
first we create x center coordinate field (the same for y) in the attribute
table manually, then we will run this code.
'''
list1 = []
listToDeleteX = []
listToDeleteY = []
fc = r"G:\desktop\Project\lyr\polygon.shp"
# check the x coordinate
with arcpy.da.UpdateCursor(fc, "xCenter") as cursor:
for row in cursor:
list1.append(row)
if list1.count(row)>1:
listToDeleteX.append(row)
# check the y coordinate
with arcpy.da.UpdateCursor(fc, "yCenter") as cursor:
for row in cursor:
list1.append(row)
if list1.count(row)>1:
listToDeleteY.append(row)
listToDeleteY.append(listToDeleteX)
in the end of the code i added the x list to the y list but i don't know how to delete the duplicated rows.
I work with arcGIS for Desktop so i don't have any extensions and i can't use the "arcpy.DeleteIdentical_management" tool.
This is the attribute table of the polygon layer:
Best Answer
This code will work on a table and searches a numeric field called test to find and delete duplicates. It assumes the first instance of a duplicate value is the one you want to keep.
One thing to consider, I have found deleting from very large datasets (e.g. millions of rows) can be very slow. It is much quicker to copy out rows you want to keep into a new dataset.