I need a line of code that will issue new sequential id's based on the order I've prescribed to my data. Essentially, after having sorted my data to my liking, the original Object_Id's are no longer in a meaningful order to me. In my table I created a new field (short integer). In the pre logic script box of the field calculator I attempted the following:
counter = 0
def uniqueID():
global counter
counter += 1
return counter
But it didn't seem to work.. A little sample of what my table looks like is as follows: (for visualization purposes)
Object_ID / MMSI / TIME / VESSEL / NEW_ID
1210 4444 01/10/10 01 NuLL
1801 4444 02/10/10 01 NuLL
303 4444 03/10/10 01 NuLL
2839 4444 03/10/10 01 NuLL
32100 5555 01/10/10 03 NuLL
34 5555 02/10/10 03 NuLL
In essence I need those NuLL's to now be 1, 2, 3, 4... etc etc. as my data is now ordered to my liking (first by MMSI number/within MMSI by date)
So, it would look as follows after: (notice the New_ID field is now populated)
Object_ID / MMSI / TIME / VESSEL / NEW_ID
1210 4444 01/10/10 01 1
1801 4444 02/10/10 01 2
303 4444 03/10/10 01 3
2839 4444 03/10/10 01 4
32100 5555 01/10/10 03 5
34 5555 02/10/10 03 6
how would I accomplish this? thanks
There's a field calculator sample in the ArcGIS Help that does exactly what you want.
http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000004s000000
(If that link doesn't work for you just search for "calculate field examples" in the ArcGIS help).
Scroll down to "Accumulative and sequential calculations".