Skip to content
Prev 2347 / 29559 Next

map algebra with ascii grid

As Roger mentioned, we did try to make the Spatial*DataFrame objects 
behave like a data.frame but indeed not with respect to applying direct 
arithmetric on them. I do agree with Tim that if a is a single-band 
SpatialGridDataFrame, then

a = a + 1

is more straightforward than

a$band1 = a$band1 + 1

although the latter does better reveal what's going on inside; the full 
story is of course that

a at data$band1 = a at data$band1 + 1

which make things pretty unreadable. In addition, if b is a single-band 
SpatialGridDataFrame only

a = a + b

could allow for checking that a and b are identical spatial grids, in 
contrast to

a$band1 = a$band1 + b$band1

So, yes, I like it, and it will break where a or b contain mixed double 
and factor variables, as it should.

The full map algebra, as I have been taught, includes besides 
arithmetical and logical operation the full set of useful functions (for 
both floats and factors) that take neighbouring cells into account, 
where neighbourhood can be global, a regular window or defined by 
another map (e.g. the land use category we're in). For an example of a 
list of functions, see for instance the work of my Utrecht colleagues:

http://pcraster.geog.uu.nl/documentation/pcrman/r2850.htm

where e.g. distance calculation is called "spread" with a constant 
friction map.

Now that would be nice to have in R.
--
Edzer
Tim Keitt wrote: