I'm trying to create a new raster from an existing slope raster where slopes are between 5 and 20 degrees. However, I'm receiving the error "ValueError: The truth value of a raster is ambiguous. Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable."
It's obvious it just has to do with my Map Algebra syntax, but I can't figure it out. Here's a snippet of my code:
slope - Slope("elevation") # creates slope raster, elevation is raster object
goodslope = (slope < 20) & (slope > 5)
goodslope.save("Final")
Maybe I have to use a Con() statement?
NameError: name 'slope' is not defined
as the slope variable is not getting defined in theslope - Slope("elevation")
line (notice the-
symbol instead of the=
symbol).slope
correctly)? Your code works fine for me in 10.2.2. I get the ValueError: The truth value of a raster is ambiguous... exception if I don't have parentheses around the(slope < 20)
and(slope > 5)
relational expressions, i.e.goodslope = slope < 20 & slope > 5
. This is because Boolean (~, &, ^, |) operators have a higher precedence level than Relational (<, <=, >, >=, ==, !=) operators.