Dear R Users,
could you please advise me on doing map algebra with spatial
grids? It's
the first time I am using spatial objects in R. I have imported an
ascii
grid file and wanted to round the values in it or sum with a
value, but it
gives an error message:
require(maptools)
x <- readAsciiGrid(fname="xxxx.asc")
x+3
Error in x + 3 : non-numeric argument to binary operator
Error in round(x, digits) : Non-numeric argument to mathematical
function
Arithmetic operations are not defined for SpatialGridDataFrame
operations,
as the columns of the data frame (here a single column) may contain
data
of different classes. Do the operations on the columns directly:
names(x)
If there is a column called "band1", then
x$band1 + 3
will print "band1" + 3, and
x$band1 <- x$band1 + 3
will add 3 to the "band1" column. Think what would happen if band1 was
categorical or logical to see why doing arithmetic directly isn't
such a
good idea.
Hope this helps,
Roger
Thank you for any suggestions.
Best wishes,
Michal