I'd like to have a tool or quick python script to classify an existing number field to a new text field. For example I have a roads layer that has a type identifier as a coded number and I would like to create a new field that described the number code as text. So say the existing field 'FCODE" had code "210" , and I want to write "Highway" in a new field "Type" and do that for multiple number-text pairs. I could select by attribute and classify that way but it would be nice to do it all in one step.
-
I answer a question that is almost the same here: gis.stackexchange.com/a/151591/53920 – Aaron P Jun 19 '15 at 19:22
If you want this as a python script, then you could do something with an update cursor...
inputData = "" #Needs to be the full path
codeField = ""
updateField = ""
with arcpy.da.UpdateCursor(inputData, [codeField, updateField]) as updateRows:
for row in updateRows:
if row[0] == "TestValue1":
row[1] = "NewValue"
elif #... etc
else:
#If you want, put something here to catch any values outside of your test
updateRows.updateRow(row)
You could also do it in the field calculator using a code block, make sure to check off the python Parser and select "Show Codeblock". In the Code Block box put:
def test(testField):
if testField == "TestValue1":
return "NewValue"
elif testField == "TestValue2"
return "NewValue2"
elif #... etc
Then where it says "FIELD NAME =" (the update field) put:
test(!testFieldName!)