Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

i have a challenge with my time in my work, i have feature class called "Parcel" storing many data, i generated an autoIncrement number by using field calculator, in field "parcel code"

Expression: autoIncrement()

Expression Type: PYTHON_9.3

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

that i asked here before How to add automate values to attribute field?

i want to start number to 001......009, and 010.........099,
thank you

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You need to use zfill function, like in the code below, zfill function fill zeros in the left of the string:

Expression:
autoIncrement()

Expression Type:
PYTHON_9.3

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 str(rec).zfill(3)
share|improve this answer
1  
wooooooooooooooow, thank you very much @geogeek, you solved spend many time, instead of doing it manually, thank you again. –  GIS Man Dec 24 '13 at 9:39
1  
Here is a version that uses a generator function rather then a if and global gist.github.com/NathanW2/8113514 –  Nathan W Dec 24 '13 at 13:44
    
ok, thank you very much@Nathan W, it is a good idea. –  GIS Man Dec 24 '13 at 16:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.