Is there a convenient (or even effective) method for recoding field values using the field calculator or standalone python script?
In this case, I am given several unique strings to identify a type of road feature. For the purpose of creating a unique ID-based join field, I want to give each road type a number to act as its equivalent when matching and classifying. I would like to avoid using cursors, as I have been told that cursors are inefficient for large data processing (in this case, the table is a few million records). However, if necessary, it will be better than the alternative of doing it by hand.
Perhaps there is a way to create a dictionary at runtime, establishing a field value and its numerical code by sequential steps when processed? For example, creating a key-value pair for a value the first time it is encountered in the dataset being processed?
I apologize if this is a duplicate question, but I was unable to find anything even remotely similar via search or the ESRI forums.
For example:
Say we have a shapefile of road line links called "Roads" with attributes "Type" and "TypeCode". If there are 3 types "Foo", "Bar", and "Other", I would like the calculation to assign the number 1 to whichever type it encounters first, and fill "TypeCode" with 1 for each successive row that contains the same type. It would do the same for the other two types, assigning 2 and 3 based on order encountered and fill the "TypeCode" for the appropriate rows.
In an attempt to make things more clear, another way of explaining what I'm looking for:
With a table of polyline road links, we have two fields, STYLE and STYLE_CODE:
------------[STYLE]----------[STYLE_CODE]
Feature 1 -- [4WD]----------------[]
Feature 2 -- [DIVIDED]------------[]
Feature 3 -- [HIGH CLEAR]---------[]
Feature 4 -- [4WD]----------------[]
The point is to have the hash table created after being given a set of data. In this case, the script would see Feature 1's Style as the first ocurrence of the Style and assign it an arbitrary unique value (Let's say the value is 1). Feature 2's Style would also be the first occurence, so the script assigns it the value 2. Feature 3's Style gets the value 3. When Feature 4 is iterated, the script already has a value set for the key 4WD, so it assigns a 1 to the STYLE_CODE field again. This continues until the end of the table.
Result:
------------[STYLE]----------[STYLE_CODE]
Feature 1 -- [4WD]----------------[1]
Feature 2 -- [DIVIDED]------------[2]
Feature 3 -- [HIGH CLEAR]---------[3]
Feature 4 -- [4WD]----------------[1]
I'd like to create a ubiquitous script that processes a table in this fashion. Sure, I only have to make the hash table once per product if I do it by hand, but making it for every product will eat up too much time.