I'd like to do some complicated field calculation.
I want to calculate the Field 6-value (see table below, representing a FeatureClass table) as follows:
If Field 1 = 617: Field 3-value
Else: Field 2-value
If Field 4 = ABC:
If Field 5 is Null:
"Someothertext" + Field 5
I entered the results in Field 6 as an example
|Field 1||Field 2||Field 3||Field 4||Field 5||Field 6|
|611||from July 1||April to November||TextWith_äöü||from July 1 | Sometext|
|612||from July 1||April to November||ABC||TextWith_äöü||from July 1 | Someothertext TextWith_äöü|
|612||from July 15||April to November||ABC||from July 15 | Someothertext|
|617||from July 1||April to November||ABC||April to November | Someothertext|
Up until now, I exported the table and calculated the value with some "when"-statements in Excel. But since I'd like to have the results in GIS i searched for an other solution.
I ended up using "arcpy.CalculateField_management" and something like this:
def compare(class1, class2, class3):
if class1 in (612, 611):
elif class1 == 617:
# Expression below
compare(!some_field!, !another_field!, !another_field2!)
This didn't work quite well because
- the code will become huge (I have more fields and values to compare)
- there seem to be problems with converting/using characters which don't fit into ASCII
- i couldn't figure out how to ask properly if Field 5 is Null
- I could not properly translate the "AND" and the "OR" from Excel to Python (for example: If Field 4 is Null AND Field 5 is Null AND Field 1 is 612, Field 6 = ...)
Is there an other, easyer solution how I can calculate Field 6 value?
Thanks a lot for your help!