[R-sig-Geo] map algebra with ascii grid
Roger Bivand
Roger.Bivand at nhh.no
Sat Jul 14 14:16:49 CEST 2007
On Sat, 14 Jul 2007, Michal Gallay wrote:
> 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
>> round(x,2)
> 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
>
>
>
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list