Python problem 'Calculate Field'

279
3
Jump to solution
08-08-2012 02:14 AM
VeronicaMartin_Martin
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.
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
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>

View solution in original post

0 Kudos
3 Replies
JakeSkinner
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>

View solution in original post

0 Kudos
VeronicaMartin_Martin
New Contributor
wow!!! that works perfectly!!!!!

Thank you veeery much!
0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor
login and mark the thread as being answered so that others know that the issue was resolved
0 Kudos