[GIS] Using python elif syntax in Field Calculator to reclassify a range of values from a different field and populate a new field

arcgis-10.0arcgis-desktopfield-calculatorpythonshapefile

I'm trying to use the Field Calculator with a python elif statement to reclassify values from a different field and populate a new field, and while I'm not getting an error message of any kind, I'm also not getting any sort of result. In other words, the tool runs and it says that it succeeded but nothing has changed in the column that is being calculated.

In codeblock example below the column that I want to use the elif statement on is "pa_gNyr_ha" and the new column that I want to populate is "N_load_bin".

def Reclass(Nload):
  if (Nload >= 0 and Nload <= 10000):   
    return 5000  
  elif (Nload > 10000 and Nload <= 24000):    
    return 17000  
  elif (Nload > 24000 and Nload <= 40000):    
    return 37000
  elif (Nload > 40000 and Nload <= 58000):
    return 50000
  elif (Nload > 58000 and Nload <= 74000):
    return 66000
  elif (Nload > 74000 and Nload <= 90000):
    return 82000
  elif (Nload > 90000 and Nload <= 104000):
    return 97000
  elif (Nload > 104000 and Nload <= 118000):
    return 111000
  elif (Nload > 118000 and Nload <= 130000):
    return 124000
  elif (Nload > 130000 and Nload <= 142000):
    return 136000
  elif (Nload > 142000 and Nload <= 157000):
    return 149500
  elif (Nload > 157000 and Nload <= 173000):
    return 165000
  elif (Nload > 173000 and Nload <= 189000):
    return 181000
  elif (Nload > 189000 and Nload <= 210000):
    return 194500
  elif (Nload > 210000 and Nload <= 233000):
    return 221500
  elif (Nload > 233000 and Nload <= 261000):
    return 242000
  elif (Nload > 261000 and Nload <= 299000):
    return 280000
  elif (Nload > 299000 and Nload <= 356000):
    return 327500
  elif (Nload > 356000 and Nload <= 456000):
    return 406000
  elif (Nload > 456000):
    return 501500

And then the expression is

Reclass(!pa_gNyr_ha!)

Essentially what I'm trying to do is create a conditional statement that will look at a value in the "pa_gNyr_ha" field and return a value to the "N_load_bin" field based on the range it falls into.

Am I at least close?

Best Answer

See PolyGeo's 1st comment to the original Question.

I was trying to use the Field Calculator and python codeblock on a shapefile and it worked as expected when the shapefile was exported to a geodatabase and the tool run on that file geodatabase feature class. PolyGeo rules.

Related Question