Using ArcGIS 10.7 desktop.
I want to reclassify a land use field using Field Calculator. Grasslands are conditionally reclassified using a 'veg_type' field (Avena, or Bromus) and a CWHR land use field (grassland values = Annual Grassland, AGS, Perennial Grassland). All other values in the CWHR field should stay the same.
When I run the Python Parser syntax the Grassland_Reclass field returns "Avena Grassland" (gridcode = 1) for the assigned land use values, but also for grasslands categorized as "Bromus' (gridcode = 0). The default CWHR values are added, but the elif condition (gridcode = 0) is not returned. I've also tried with the veg_type field but I get the same result.
def Reclass(gridcode, CWHR_TYPE):
if gridcode == 1 and CWHR_TYPE == "Annual Grassland" or CWHR_TYPE == "AGS" or CWHR_TYPE == "Perennial Grassland":
return "Avena Grassland"
elif gridcode == 0 and CWHR_TYPE == "Annual Grassland" or CWHR_TYPE == "AGS" or CWHR_TYPE == "Perennial Grassland":
return "Bromus Grassland"
else:
return CWHR_TYPE
Expression: Grassland_Reclass =
Reclass(!gridcode!, !CWHR_TYPE!)
gridcode
, given the rest to the right hand side is the same. Also, pyhon hasin
operator and it is great replacement for multipleor
s and easier to read, e.g.,CWHR_TYPE in ("Annual Grassland", "AGS", "Perennial Grassland")
CWHR_TYPE
is "Annual Grassland
") the correct language to use isSQL
. Do not use python. UseSQL
.SQL
is quite literally, designed to do nothing but manage tables of data.