Select to view content in your preferred language

# Python problem 'Calculate Field'

601
3
08-08-2012 02:14 AM
New Contributor
Hi all,
I'm just starting with Python and I'm a bit stuck... so sorry if the question is very basic, but I cannot find it anywhere. I'm working with ArcGis 9.3

I am developing a model builder, in one step I have to calculate a field (field3) based on two other different fields, lets say
[FIELD_1= a, b, c, d???] and [FIELD_2= 1, 2, 3..].

From here no problem, the point is that FIELD_3 takes different values depending on Field_1 value.
For one unique value in FIELD_1 I have the following code working properly

[ATTACH=CONFIG]16760[/ATTACH]
def Reclass(FIELD_2):
if (FIELD_2 < 92):
return 0
elif (FIELD_2 >= 92 and FIELD_2 < 93.5):
return 1
elif (FIELD_2 >= 93.5):
return 2

The problem is that I don???t know how to add that if ???FIELD_1== 1 or 2 or 4??? do the calculation above, but if FIELD_1 == 3, 5, 7 do a different one.

Any help would be really helpful
Thank you very much in advance!!

Veronica.
Tags (3)
1 Solution

Accepted Solutions
Esri Esteemed Contributor
Hi Veronica,

You could do something like the following:

`def Reclass(FIELD_1, FIELD_2):   if FIELD_1 == 1 or FIELD_1 == 2 or FIELD_1 == 4:     if (FIELD_2 < 92):       return 0     elif (FIELD_2 >= 92 and FIELD_2 < 93.5):       return 1     elif (FIELD_2 >= 93.5):       return 2   elif FIELD_1 == 3 or FIELD_1 == 5 or FIELD_1 = 7:     <other code>`
3 Replies
Esri Esteemed Contributor
Hi Veronica,

You could do something like the following:

`def Reclass(FIELD_1, FIELD_2):   if FIELD_1 == 1 or FIELD_1 == 2 or FIELD_1 == 4:     if (FIELD_2 < 92):       return 0     elif (FIELD_2 >= 92 and FIELD_2 < 93.5):       return 1     elif (FIELD_2 >= 93.5):       return 2   elif FIELD_1 == 3 or FIELD_1 == 5 or FIELD_1 = 7:     <other code>`
New Contributor
wow!!! that works perfectly!!!!!

Thank you veeery much!
MVP Emeritus
login and mark the thread as being answered so that others know that the issue was resolved