I am trying to populate a unique identifier field "STD_ID" using arcpy.da.UpdateCursor. The identifier would be an iterative 1,2,3 and would reset the iteration based on region ID in which the polygon is located "RBSB_ID2"
My problem is I can't figure out how to reference the next row to restart the iteration. I updated the for loop to include cursor.next(), the error is now that I never started the iteration.
#call stands layer and define variables stands = "F:/ArcGIS/Data/ForestPlanning.gdb/NYC_Stands" rbsb_std = ('RBSB_ID2', 'STD_ID') #define iteration. iteration = 0 #create cursor for Stand IDs using arcpy.da.UpdateCursor with arcpy.da.UpdateCursor(stands, rbsb_std) as cursor: for row in cursor: try: next_row = cursor.next() except StopIteration: next_row = row if row != next_row: row = 1 else: row = iteration + 1 iteration = iteration + 1 cursor.updateRow(row)
Any ideas on how to fix this?
- I just edited the code to reflect toslunds original answer.
In response to the desired output ... assume
RBSB_ID2 = [100023, 100023, 100023, 100144, 100144, 1000144, 1000144, 1001512, 1001512] #The output for 'STD_ID' would be: STD_ID = [1, 2, 3, 1, 2, 3, 4, 1, 2] #The next step would be to convert to STD_ID to a string & later convert to something like #[001, 002, 003, 001 ...] and then later concatenate with the RBSB_ID to #create a unique id for each row that links RBSB_ID2 with STD_ID. #RBSB_STD_ID = [100023001, 100023002, 100023003, 100144001, ...]