I've been searching high and low for this (Stackoverflow/exchange, etc, Geonet...). Here it goes. I have a table with a number of records. I have a field called 'Rotation' I would like to populate with a repeating set of values [0,90,180,270]. So imagine the following:
PT_ID | ROTATION |
---|---|
1 | 0 |
2 | 90 |
3 | 180 |
4 | 270 |
5 | 0 |
6 | 90 |
7 | 180 |
8 | 270 |
9 | 0 |
I've tried to simplify my question as much as possible, but its literally as simple as that. Most of the searches return information related to deleting duplicate/repeated records & values.
Solved! Go to Solution.
Haven't tested but something like:
>>> from itertools import cycle
>>> rot = cycle((0,90,180,270))
>>> with arcpy.da.UpdateCursor(in_table,["PT_ID","ROTATION"]) as cur:
... for row in cur:
... row[1] = next(rot)
... cur.updateRow(row)
Haven't tested but something like:
>>> from itertools import cycle
>>> rot = cycle((0,90,180,270))
>>> with arcpy.da.UpdateCursor(in_table,["PT_ID","ROTATION"]) as cur:
... for row in cur:
... row[1] = next(rot)
... cur.updateRow(row)
Joshua, this is exactly what I needed, thanks!!!
Go with Joshua's answer, I was just curious to see how hard this would be in Field Calculator (as long as your IDs are reliable):
VB Script (but could do the same in Python): (([PT_ID]-1)*90)-( Int(([PT_ID]/4)-0.25) *360)