You're gonna have to give more info than that. And no, that method won't work.
symbol_weights = { 6: 1.2, 85: 1.5, 2: 1.0, 42: 1.8, 58: 2.0, }
symbol_weights[!SYMBOL!]
Just a suggestion, but if this is part of a Python script, you are WAY better off using an updatecursor instead. The benefit is readability, codeability, and debugging. The code block for the FieldCalculator is notoriously hard to write code for, while the updatecursor has very clear and clean syntax
KLAScodeblock = "If [CMPAREA] <= 1000 Then\\nklasse = 100\\n\\nElseif [MIN] <= "+MDV+" Then \\nklasse = 1\\n\\nElseif [MIN] <= "+MDA+" Then \\nklasse = 2\\n\\nElse \\nklasse = 3\\n\\nEnd If\\n\\n\\n"
This goes in the code block: symbol_weights = { 6: 1.2, 85: 1.5, 2: 1.0, 42: 1.8, 58: 2.0, } And in the expression field you put: symbol_weights[!SYMBOL!]
Parser: Python Expression: getRandomValue() Code Block: import numpy.random as R def getRandomValue(): return R.random()
I tested it and got the same error, and I still don't understand why. But I found an easy workaround: Rename the dictionary to something else (without underscore) like symweights. Do that both in the code block and the expression field and it works.
That works perfect. Like Python should! Amazing. I choose this method, because I wanted to use the ModelBuilder. Not sure if a cursor would work in this case.
symbol_weights = { 6: 1.2, 85: 1.5, 2: 1.0, 42: 1.8, 58: 2.0, } cur = arcpy.UpdateCursor(my_feature_class) for row in cur: row.Weight = symbol_weights[row.SYMBOL] cur.UpdateRow(row)
Hi Ryan,
When you define the method within the Python codeblock, use a variable for the Reclass method's parameter and use that variable within the method's logic:
def Reclass(weight):
if (weight == 6):
return 1.2
elif (weight == 85):
return 85
.....
Then when you call the Reclass method in the Calculate Field Expression parameter, you will then pass in the SYMBOL field:
Reclass(!SYMBOL!)
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.