If you were to use a script it could calculate all the fields at once. If you were to use the field calculator you'd have to run it on each field you want to update (5x).
The following script will update your Dom fields in order of the values of your landcover fields. If several fields have the same value, each field name will be appended as per your example. I tested the script on the dumby data, and it works for me. That said, it might not be the most efficient method.
EDIT: The script now dynamically pulls the field names from your dataset. It looks for "PRC" in the field name to denote a landcover type and "Dom" for a dominant field. Only fields with values greater than zero are written with the remaining Dom fields left blank.
There are quite a few decimal places so the only repeated values (according to the dummy data you dropboxed) are zeros. Maybe this is different on the whole dataset so I couldn't test the section that writes multiple field names to a column.
import arcpy
# Put the absolute path to your table / feature class
theData = r"C:YourPathHere"
# Create empty Python list, and a list of field names
values = []
fields = []
domFields = []
# Get all landcover and Dom field names dynamically
for field in arcpy.ListFields(theData):
if 'PRC' in field.name:
fields.append(field.name) # Grab all fields names that contain "PRC"
elif 'Dom' in field.name:
domFields.append(field.name)
# Arcpy Update cursor
rows = arcpy.UpdateCursor(theData)
# Loop through each row in your attribute table
for row in rows:
i = 0
while i < len(fields):
# Store the fieldname and value in a tuple, add to list ex. [("PRC_Water", 5), ("PRC_Bare", 10), etc.]
values.append((fields[i], row.getValue(fields[i])))
i += 1 # iterate counter
# Sort the list of tuples based on the integer value in descending order
values = sorted(values, key=lambda value: value[1], reverse=True)
sortedFields = [x[0] for x in values] # Grab the ordered field names
sortedValues = [x[1] for x in values] # Grab the ordered field values
# Set the values of Dominance fields based on the order of the list
j = 0
while j < len(domFields):
if sortedValues[j] > 0:
row.setValue(domFields[j], sortedFields[j])
else: # if the next greatest value is zero, leave the field blank
row.setValue(domFields[j], "")
j += 1 # iterate counter
rows.updateRow(row)
# This section handles cases where multiple landuse values are equal
k=0
while k < len(fields):
fieldsEqual = ""
startRepeat = 0
numRepeat = 0
# If two fields contain the same value...
if sortedValues.count(sortedValues[k]) > 1:
# Find the position in the list where they begin to repeat (repeated values will occur back-to-back)
startRepeat = sortedValues.index(sortedValues[k])
# Find the number of times the value is repeated
numRepeat = sortedValues.count(sortedValues[k])
l = 0
# While the counter is less than the number of repeated values, append the field name to a string
while l < numRepeat:
fieldsEqual += sortedFields[startRepeat + l]
# Add a comma and space to each value except the last one
if l < numRepeat - 1:
fieldsEqual += ", "
l += 1 # iterate counter
# Write the fields with equal values into the Dom fields
m = 0
while l < numRepeat:
row.setValue(domFields[startRepeat + m] , fieldsEqual)
rows.updateRow(row)
m += 1 # iterate counter
k += 1 # iterate counter
# Clear the list for the next row of data
values = []
# Delete cursor objs
del row, rows