1

I am new to python ArcPy. I am trying to delete identical points in feature class. the code is below:

>>> import arcpy
>>> fp=r"D:\NOCAS\TEMP\Belgum transistion.gdb\transistion\CenterlinePoints"
>>> sc=arcpy.da.SearchCursor(fp,["oid@","shape@"])
>>> dictionary={}
>>> for data in sc:
...     dictionary[data[0]]=data[1]
...     
>>> uc=arcpy.da.UpdateCursor(fp,["oid@","shape@"])
>>> for row in uc:
...     for r in dictionary:

...         if row[0]!=r:

...             if sd[r].equals(row[1]):

...                 uc.deleteRow()

when trying to run the code it delete one point out five identical points and arcmap shutdowned.

4
  • It sounds like a self locking situation, use a with statement, as it stands your search cursor isn't gone and is still locking when you get to the update cursor. with arcpy.da.SearchCursor(fp,["oid@","shape@"]) as sc: then for data in sc:, for the update cursor use with arcpy.da.UpdateCursor(fp,["oid@","shape@"]) as uc: then for row in uc: this will ensure the locks are being released. Commented Mar 8, 2019 at 7:20
  • 1
    Why don't you just use the delete identical tool, no need for any code?
    – Hornbydd
    Commented Mar 8, 2019 at 9:58
  • i am new to arcpy i just trying to use updatecursor Commented Mar 8, 2019 at 10:48
  • i write code with with arcpy.da.SearchCursor(fp,["oid@","shape@"]) as sc: then for data in sc:, for the update cursor use with arcpy.da.UpdateCursor(fp,["oid@","shape@"]) as uc: then for row in uc: but still not running Commented Mar 8, 2019 at 10:49

1 Answer 1

2

You have the potential to try to delete the same row twice since you have a for occuring in each row. break out of your for loop if a deleteRow occurs.

>>> for row in uc:
...     for r in dictionary:
...         if row[0]!=r:
...             if sd[r].equals(row[1]):
...                 uc.deleteRow()
...                 break
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.