Tuesday, 16 October 2018

field calculator - Using arcpy.CalculateField_management


I have a table with a column named "Kategorie", filled with values. I added a new column named "RULE". I want to fill this column with Strings depending on "KATEGORIE". I have a PY-Script and it doesn't work.


What is wrong?


Expression:



"getKat(!KATEGORIE!)"

Codeblock:


"""def getKat(KATEGORIE):
if KATEGORIE = "0":
myval = "Autobahn"
if KATEGORIE = "1":
myval = "Bundesstrasse"
else:
myval= 3"""

arcpy.CalculateField_management(ERG, "RULE", expression, "", codeblock)



Both answers so far don't work. I think the problem is the line "expression" or "codeblock". I try to print the result of "myval".The result is a error message "name myval is not defined"


expression:


"getKat(!KATEGORIE!)"

codeblock:


"""def getKat(KATEGORIE):
if KATEGORIE == "0":

myval == "Autobahn"
elif KATEGORIE == "1":
myval == "Bundesstrasse"
else:
myval == "3"
return myval"""
print "myval", myval
arcpy.CalculateField_management(ERG, "RULE", expression, "PYTHON", codeblock)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...