The aim is to perform a multicriteria-analysis in which I use 3 columns in a dataset (dataset
) and 3 weight settings, each one relating to one column. A new column (MCA
) equals the result of the multicriteria-analysis. ArcPy is the opted method to achieve this. Imagine that I have the following weight settings for every column (being columnA
, columnB
, and columnC
).
#parameter settings
weight_columnA = 0.3
weight_columnB = 0.4
weight_columnC = 0.2
Total_weight = weight_columnA + weight_columnB + weight_columnC
Now a 'fixed' calculation would be feasible:
arcpy.management.CalculateField("dataset", "MCA", "(!columnA! * 0.3) +( !columnB! * 0.4) + (!columnC! * 0.2)/0.9", "PYTHON3", '', "TEXT", "NO_ENFORCE_DOMAINS")
However, the weight settings should be easy to change, based on the user needs, so that a more dynamic approach should be realized. To encourage this dynamic approach, I would like to insert the defined weight variables into my formula. However, this does not work via this way:
arcpy.management.CalculateField("dataset", "MCA", "(!columnA! * weight_columnA) +( !columnB! * weight_columnB) + (!columnC! * weight_columnC)/Total_weight", "PYTHON3", '', "TEXT", "NO_ENFORCE_DOMAINS")
Also, inserting str()
(e.g. str(weight_columnA)
before the variables does not work.
What is a workaround so that the defined variables (i.e. weights) can be implemented successfully into the field calculator, using ArcPy?