Hi!
I'm trying to add the polygons of lines that applied certain criteria to the last row and delete all the row beside the last one.
The problem is that it is very slow.
When I run debugger it turns out that "for row in cursor:" is stuck for a long time after finishing the last item.
I mean, the line "cursor.updateRow(row)" is executed only in the last item. after that the debugger goes back
to the line "for row in cursor:" and stays there for a few minutes.
Why is this happens?
with arcpy.da.UpdateCursor(my_layer, field_names, '"SETTLEMENT" = ' + str(x) ) as cursor:
numberOfLinesLeft = sum(1 for row in cursor)
cursor.reset()
flag=0
for row in cursor:
if flag==0:
temp_shape = row[0]
flag=1
else:
temp_shape = temp_shape.union(row[0])
if numberOfLinesLeft > 1:
cursor.deleteRow()
numberOfLinesLeft -=1
else: # We reached the last row, In this row we need to update it's shape
row[0]=temp_shape
cursor.updateRow(row)