Increment Field in Sorted Table

3656
12
Jump to solution
10-30-2017 03:47 PM
JoeBorgione
MVP Emeritus

I've seen a few posts here and on stack exchange that mention this topic, but when I use the code provided it fails. This seems pretty straight forward:

counter = 1
while counter < 11:
  print (counter)
  counter += 1

 and when in an idle window, returns :

1

2

3

....

10 

 As expected.  However, if I put something like that in the field calculator, I get 000539 Error.  It seems that any auto-incrementer I've found online has a dependency on the OID in way or another.  I've tried a da.UpdateCursor, and CalculateField_managment:  

arcpy.CalculateField_management("Streets","CoordSortValue","+=1","PYTHON")

with no luck.

Is it possible to sort a table, and then calculate the position each record has in the sort?

That should just about do it....
0 Kudos
12 Replies
JoshuaBixby
MVP Esteemed Contributor

I agree with Dan, this can most certainly be done, and there are multiple ways to do it.  If you can provide more details about your situation, especially some example/sample data, I am quite sure the community hear can come up with a solution.

RandyBurton
MVP Alum

It might be worthwhile to ask this as a new question since this thread is 2 years old and is marked as answered.  You can link to this question so that everyone knows what you have tried.

0 Kudos
MatthewDuffy
Occasional Contributor II

Many thanks all.  I did just what you suggested and something went wrong with my browser and I lost the draft of my question.  I'm at work now so I can't spend time right now re-doing this post, but I'll try to send a reply with a new question over the weekend.  Many thanks to you all for replying so quickly.  We have a great community here and it is a direct result of all of your quick replies, ideas and responses.  Thank you