calculate feild using phyton if function

778
5
Jump to solution
06-28-2021 09:00 AM
matu89
by
New Contributor II

hello, i want to calculate feild using phyton if function to do the following :

if Height_Delta is greater than 0 write in the status cell " Uprise"

if Height_Delta is less than 0 write in the status cell "Downrise"

image is attached

444.PNG

can anyone can help with the code ?

thanks.

 

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor
["Down_rise", "Up_rise"][!Height_Delta! > 0]

goes under Status =  line

not in the code block

some background

Fundamentals of field calculations—ArcGIS Pro | Documentation


... sort of retired...

View solution in original post

0 Kudos
5 Replies
DanPatterson
MVP Esteemed Contributor
Height_Delta = 5  # ---- example value

["Down_rise", "Up_rise"][Height_Delta > 0]
'Up_rise'

Remember to put ! marks around Height_Delta ( !Height_Delta! ) since it is a python field calculator expression


... sort of retired...
0 Kudos
matu89
by
New Contributor II

can u tell where to write each line of the code in the feild calculator window ?

 

image is attached here :

555.PNG

 thank u 

0 Kudos
DanPatterson
MVP Esteemed Contributor
["Down_rise", "Up_rise"][!Height_Delta! > 0]

goes under Status =  line

not in the code block

some background

Fundamentals of field calculations—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Another alternative.

Expression:

 

Slope(!Height_Delta!)

 

 

Code Block:

 

def Slope(HT):
    if HT< 0:
        return 'Downrise'
    else:
        return 'Uprise'

 

 



Think Location
0 Kudos
DanPatterson
MVP Esteemed Contributor

expression

code_block(!Height_Delta!)

code block

def code_block(fld)
    """code block isn't really needed"""
    return ["Down_rise", "Up_rise"][fld > 0]

but as you can see it really isn't needed

 


... sort of retired...
0 Kudos