IF statements to rank different ranges with field calculator in ArcMap

arcgis-10.6arcgis-desktoparcmapfield-calculatorpython-parser

I have a simple calculation to perform using the Python Parser in ArcMap but am running into some trouble when it comes to coding the ranges of values.

I have three different fields: mean temperature, altitude, and precipitation that I would like to reclass. For example,

if temperature is >= 18 and altitude <650 and precipitation >= 1200 then write Optimal

if temperature is < 12 and altitude >=1300 and precipitation is <900 then write Unsuitable

if mean temperature is between 12-17 and altitude is between 650-1299 and precipitation between 900-1199 then write sub-suitable.

I get stuck at the last class when trying to do the code for calling up within a ranges of values. Finally, I have added a new field for the classes called MC_Clim.

This is the code I have come up with so far:

def Reclass(temperature,altitude,precipitation):
       if tmean>= 18 and altitude< 650 and prec13>= 1200:
          val= "Optimal"
       elif tmean < 12 and altitude >= 1300 and prec13< 900:
          val= "Unsuitable"
      

Expression:
     Reclass (!temperature!,!altitude!,!precipitation!)

Best Answer

You are close. I believe you just need to return your desired text string. And make sure argument names match your variable names (if mean temperature and temperature are different columns, be sure to include them as separate arguments)

def Reclass(temperature,  altitude, precipitation):
   if temperature >= 18 and altitude < 650 and precipitation >= 1200:
      return "Optimal"
   elif temperature < 12 and altitude >= 1300 and precipitation < 900:
      return "Unsuitable"
   # to test if a value is inside a range
   elif 12 < temperature < 17 and 650 < altitude < 1299:
      return "Sub-suitable"
   return "N/A"    


## here you include column names as arguments 
Expression:
     Reclass (!tmean!,!altitude!,!prec13!)

enter image description here

Related Question