Wednesday, 13 November 2019

arcmap - How to perform If Statement in Field Calculator of ArcGIS for Desktop?


I have a shapefile containing two numeric fields ("Dist_1" and "Dist_2"). I want a Field Calculation that will populate an additional field ("Result") with one of three answers:


First if Dist_1 is greater than Dist_2 populate Result with 'True' Second if Dist_1 is less than Dist_2 populate with 'False' and Third if Dist_1 and Dist_2 are equal populate with "Equal"



Answer



Parser:


Python



Code block:


def calc(f1,f2):

if f1 > f2:
return "True"
elif f1 < f2:
return "False"
else:
return "Equal"


Expression:


calc(!Dist_1!, !Dist_2!)


Or graphically (you cannot see all of the code block here unfortunately)


enter image description here


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...