mwooten3

Using a code block to Calculate Field

Discussion created by mwooten3 on Oct 8, 2013
Latest reply on Oct 9, 2013 by mwooten3
Hi. I'm trying to do something simple in Arc but with no luck and was hoping someone could point out my error.

I want to use the value of pixels (Value field) in a raster to define a new field called 'TreeClass', where 6 classes will be represented.

I built the attribute table and added the field (tried both short integer and long integer, the latter which matches the Value field type).

I use the following in the Code Block parameter for the Calculate Field tool:
def getclass(Value):
 if Value >= 0 & Value <= 10:
  return 1
 if Value >= 11 &  Value <=20:
  return 2
 if Value >= 21 & Value <= 40:
  return 3
 if Value >= 41 & Value <=60:
  return 4
 if Value >= 61 & Value <=100:
  return 5
 else:
  return 6


And enter "getclass(!Value!)" into the Expression parameter.

When I run the tool, the TreeClass field populates with 1's.

What am I doing wrong here? Any advice would be greatly appreciated. Thank you!

Outcomes