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 field calculator expression I use in QGIS to generate unique IDs that are sequential, but start with a text string. I now need to perform the same thing in ArcGIS, but I am unsure of how to start. Here is my QGIS expression:

 'cos' || ( tostring(  $rownum  + 1000000))

I was thinking that in ArcGIS it would be something like this:

 "cos"+InStr( [FID] + 1000000 )

But it returned an error.

Any help would be appreciated. Thanks...

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

There are few different ways to do this in ArcGIS Field Calculator.

If you are fine with basing the ID on the FID, you can use:

"cos" + str(!FID! + 1000000) - make sure you set Field Calculator to Python

or

"cos + CStr([FID] + 1000000) - make sure you set Field Calculator to VB

If you want your unique IDs to be sequential and not based on the FID the easiest way is to use a Python codeblock in your Field Calculation:

Codeblock:

rec = 1000000
def autoIncrement():
  global rec
  id = "cos" + rec
  rec += 1
  return id

Expression:

autoIncrement()

The above function will start at the first record in your table with cos1000000 and add 1 to each new record like cos1000001, cos1000002, etc...

share|improve this answer
    
Thank you, that was exactly what I was looking for –  Ryan Garnett May 15 '13 at 19:38
add comment

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.