3

I need to create a new integer field based on another text field. All instances of a the same text string in the existing field should be assigned the same number (starting at number 1). Can I do this in field calculator? If so, how?

I'm a beginner code-wise.

EDIT: Here's a sample enter image description here

Each place name should be assigned a number. The third column shows what I'd like as a result. This is so I can use Hawths tool BATCH FIXED KERNEL DENSITY ESTIMATOR which only works with number categories:

http://www.spatialecology.com/htools/bkde.php

NOTE: Although I'm using 10.1, I've tried the non-batch kernel density estimator and it works well, no hitches so expect / hope the batch kernel estimator will work too.

  • 1
    I think the answer to this could be the Field Calculator or Join Fields depending on what your input data and desired output look like. Are you able to post some sample records? – PolyGeo Sep 4 '13 at 9:39
  • Will pop a sample in now – Joules Sep 4 '13 at 10:52
  • 1
    I was thinking there would be two input tables and one expected output. Is this perhaps the expected output? If so should Bethnal Green have values of 2 and 3? – PolyGeo Sep 4 '13 at 11:25
  • My mistake - I've corrected and explained above. The first column is irrelevant. – Joules Sep 4 '13 at 11:44
3

Provided that you have a Text column and what to assign numbers like this:

Text    Number
aaa      1
aaa      1
bbb      2      
ccc      3
ccc      3

I would suggest the following workflow that is easy and does not require programming. Run the Frequency GP tool and specify the Text field as your Frequency field. You would get a table with all the unique values and count of how many rows have this value. This value you don't really need and can now calculate this field with the values in OBJECTID field (which has unique sequence starting from 1).

After that, you perform a join of this table to the source feature class/table based on the Text field. Now you have a field with the unique numbers for each occurence of the unique text value.

4

You could do this in the field calculator but, depending on how many different text values you have, this could get a bit tortuous. A different (and simpler) approach would be to create a look up table in NotePad or Excel containing two fields. The first field contains your unique text strings and the second is the integer code you want to relate to each one. Then save this as a CSV table, import it into your MXD and do a table join to relate the numeric value to your text values in your data.

EDIT:
You can speed up the creation of your table by getting ArcMap to spit out the unique values from your text field, then copy that into Excel and autofill the second column to generate the codes (unless you have specific values you need to ascribe).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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