FocalSum with Boolean Syntax in Raster Calculator vs. Map Algebra

355
2
11-09-2010 09:16 AM
LisaNelson
New Contributor II
Hello,

I'm trying to replicate a FocalSum process that works fine in Raster Calculator (9.3.1) but breaks when used in SingleOutputMapAlgebra_sa in Python.

Here's what works in Raster Calculator: focalsum(Not(IsNull([IndicatorRaster])),RECTANGLE,7,7)


In MapAlgebra, I get a 'Not is not a valid operator' error.  I've tried using '^' in place of 'Not' but that gives the same error.  I've played with spaces around the functions and inputs, which didn't help either.

I'm stumped now... Any insights appreciated! 

Lisa
0 Kudos
2 Replies
curtvprice
MVP Esteemed Contributor

Here's what works in Raster Calculator: focalsum(Not(IsNull([IndicatorRaster])),RECTANGLE,7,7)

In MapAlgebra, I get a 'Not is not a valid operator' error. 


Clearly the parser doesn't like that, but here's a workaround: the rule for boolean is zero is false, anything else is true. In your case, IsNull converts NoData cells to 1, and other cells to 0. So the following map algebra is functionally equivalent:

focalsum(IsNull([IndicatorRaster]) eq 0,RECTANGLE,7,7)
0 Kudos
LisaNelson
New Contributor II
Hello - just saw your response (odd, since I checked it a few times the day or two after it was posted).  Thanks for your suggestiion - I'll try in on a new set of rasters I'm processing.
0 Kudos