0

I know that this is probably a very basic question but I can't seem to find an answer through Google searches.

I would like to create a field in an attribute table (in ArcMap 10.2) for a Number Label (i.e.. 1, 2, 3, 4, ... etc.) is there a way to calculate this field with the field calculator rather than typing in each individual number?

nmtoken
  • 13,355
  • 5
  • 38
  • 87
gyoung1986
  • 528
  • 1
  • 5
  • 16
  • Does the sequence need to start at a certain record or just at the beginning of the table? – artwork21 Feb 13 '15 at 16:40
  • Info on doing either one would be useful but in this case just the beginning of the table. – gyoung1986 Feb 13 '15 at 16:40
  • 1
    This is a very common question on this site and others (a google search will give many examples). One option is to use the OID or FID column or OID + 1 or FID + 1 in Field Calculator (depending if you want to start from zero or one). – artwork21 Feb 13 '15 at 16:42

1 Answers1

3

You can use this code in field calculator to increment by 1.

Parser:
Python

Expression:
autoIncrement()

Code Block:
rec=0
def autoIncrement():
global rec
pStart = 1 #adjust start value, if req'd 
pInterval = 1 #adjust interval value, if req'd
if (rec == 0): 
  rec = pStart 
else: 
  rec = rec + pInterval 
return rec
Maksim
  • 6,916
  • 2
  • 24
  • 42
  • Could you explain this a little more? I'm not familiar at all with writing python script. – gyoung1986 Feb 13 '15 at 16:54
  • 1
    right click your field in the attribute table you want to do this calculation in, choose field calculator. Select "python" as your parser, input that code into the code block, and autoIncrement() as the expression. – Maksim Feb 13 '15 at 16:55
  • Now when I get this to kind of work copying exactly what you have here I get an error message. "Error 000989: Python syntax error: Parsing error IndentationError: expected an indented block (line 3)" – gyoung1986 Feb 13 '15 at 17:07
  • 1
    http://support.esri.com/en/knowledgebase/techarticles/detail/38517 – Maksim Feb 13 '15 at 18:03
  • 2
    If you need it sorted before incremented (happens for us sometimes), then there are a couple more steps.. See here http://gis.stackexchange.com/questions/16752/how-to-sort-a-feature-class-and-then-calculate-a-sequential-id-field for more info if that is the case. – Branco Feb 13 '15 at 20:47
  • This solution works well but it's the same as using the "FID + 1" hack. What I want is to sort my sequence according to the order of another quantitative field (say, I want to rank the areas of the features). How would I go about that? – Faustin Gashakamba Jan 14 '21 at 08:51