GIS Tips – ArcGIS, Create Sequential Numbers in the Attribute table (without using = FID!!)

Recently I was creating a HUGE figure which needed to reference all the features in the map with a number, so, as I would normally, I went to the attribute table, created a new field and opened up the ArcGIS Field Calculator, then opened up Ian Ko’s Easy Calculate (EC50 to you REAL GIS nerds) in preparation to use the “REC” command…..only it didn’t work

It turns out that EC50 doesn’t work with ArcGIS 10.1, so what did I do?……I used Python!!

Here is the ESRI resource page on how to create sequential numbers, easy peasy – even a Python noob like me got it to work!!

HowTo:  Create sequential numbers in a field using Python in the Field Calculator

Article ID: 38517
Software:  ArcGIS – ArcEditor 10 ArcGIS – ArcInfo 10 ArcGIS – ArcView 10
Platforms: N/A

Summary

Instructions provided describe how to create sequential numbers in a field using Python in the Field Calculator.

Procedure

 The code in this article generates sequential numbers for unsorted data based on the OID or FID order. If your data is sorted on a field, the generated numbers will not be sequential.
  1. Create a new short integer field.
  2. Set the Parser to Python.
  3. Select Show Codeblock.
  4. Paste the following into the Pre-Logic Script Code:
    rec=0 
    def autoIncrement(): 
     global rec 
     pStart = 1  
     pInterval = 1 
     if (rec == 0):  
      rec = pStart  
     else:  
      rec += pInterval  
     return rec
  5. Paste the following code in the smaller box below the Pre-Logic Script Code:
    autoIncrement()
  6. Click OK.

14 thoughts on “GIS Tips – ArcGIS, Create Sequential Numbers in the Attribute table (without using = FID!!)

  1. is there a way to create a sequence number begining in the left and increasing as you move to the Right? I’m not real familar with Python.

    1. Hi,

      Not quite sure what you mean. If you mean, is there a way to sequentially create a number along a line when it is in reverse order, you can do this in ArcGIS editing by selecting the line, right clicking and reverse order. Then apply the sequence routine.
      If you mean whether you can apply this across multiple fields, so that field A = 0, B=1, C=2, then you can do this easily in excel and joining the tables.

  2. hello,

    the numbering works fine, but is it also possible to have text in front of the number?

    An example would be
    QU-GO1
    QU-GO2
    QU-GO3

    QU-GOn

  3. Thank you this is a very useful script and my first fling with python. I want to start the sequence with zero but when I change pstart to zero I get all zeros. I have changed many of the parameters but nothing seems to work. I can get a nice list starting with any value other than zero and any increment that I like, I just can’t make the first feature have a zero value. Any thoughts?

    Thank you

    1. Cheat! Create a new field and run a process which takes 1 away from the culprit field 😛
      If the field is ID, then create a new column and run “[ID]-1″….then delete the original field.
      Not the best and I am sure that I could wrap it up in the python given time. Does that help?

  4. Worthless information!
    For an “unsorted” table we can obviously just make “NewIDField” = ObjectID. But how do we sequentially number a “SORTED” field? Everything I find online gives me this same (completely unnecessary) python script.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s