I have been replacing field calculations with python update cursors in many of my work flows and today I ran into a problem. The fields being updated have an attribute domain. so now, when I "calculate" the field based on the domain value, the field is not populated with the desired description. Instead it is populated with the value used in the calculation. Please see the portion of code for the update cursor.
# Get linear units
(path, name) = os.path.split(featureClass)
spatial_ref = arcpy.Describe(path).spatialReference
units = spatial_ref.linearUnitName
if units == "Meter":
lengthUOM = "Metre"
# Calculate feature class fields
rows = arcpy.UpdateCursor(featureClass)
for row in rows:
length = row.getValue("Shape_Length")
row.setValue("featureLength", length)
row.setValue("UnitOfMeasure", lengthUOM) #this field has a domain
rows.updateRow(row)
del row, rows
When I use field calculator (in an edit session) and set the value to "Metre" the field will populate with the description from the domain (what I would like). The above code, however, sets values in the field to "Metre" instead of the description. I have read this question, but it does not address update cursors.
Has anyone had any success with update cursors on fields with domains? If so, could you give me some insight into where lies my mistake? Thanks in advance for any advice.