Monday 19 August 2019

Using Python Parser in ArcGIS Field Calculator to compare two fields?


I'm trying to use field calculator to compare two fields in a table of tax parcel data, Land Value (LAND_VAL) and Improvement Value (IMPRVT_VAL). My goal is to determine (1) Parcels with land value less than the value of improvements, (2)Land value about the same value as improvements, (3) Land value more than improvement value, but less than twice the value, and (4) Land value which is more than twice improvement value.



I wrote the following script, and it runs successfully in Field Calculator (doesn't give any errors), but it only returns 4, which is clearly not the case in the data.


LV = " !LAND_VAL! "
IV = " !IMPRVT_VAL! "

def Recode(Val_Analys):
if LV < IV:
return 1
elif LV == IV:
return 2
elif (LV > IV and LV < (IV * 2)):

return 3
elif LV > (IV * 2) :
return 4
else:
return 0

Recode(!Val_Analys!)

Answer



Just put this as the script code:


def Recode(LV, IV):

if LV < IV:
return 1
elif LV == IV:
return 2
elif (LV > IV and LV < (IV * 2)):
return 3
elif LV > (IV * 2) :
return 4
else:
return 0




Recode(!LAND_VAL!, !IMPRVT_VAL!)

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