Skip to content
Prev 8019 / 29559 Next

trying to add points to a raster

Hi Roman,

The RasterLayer rst.p is correct, I think. The problem has only to do
with the plotting. The error/warning occurs because you have (a) a
relatively large RasterLayer and (b) hardly any cells have values.
Large RasterLayers are sampled (regularly) for plotting. In this case,
none of the sampled cells get a value.  You can stop this from
happening by adding a maxpixels argument to plot:

plot(rst.p, maxpixels=ncell(rst.p))

Not that it helps much; I was not able to see the difference because
there are so few cells with values (and they are still resampled to
match the screen resolution).

For visualization (only) you could make a coarser grid:

res(rst) = 10
rst.p <- pointsToRaster(raster = rst,  xy = r,   values = r at data$walker)
plot(rst.p)

Note that the default function 'fun' is length (ie. count the number
of points per cell). As you provide a 'values' argument, I assume you
want something else. To transfer the value (of the last point that is
found for a cell) you can use

rst.p <- pointsToRaster(raster = rst,  xy = r,   values =
r at data$walker,  fun=function(x){x} )

# the mean would be fun=mean, but as 'walker'  is a factor:
rst.p <- pointsToRaster(raster = rst,  xy = r,   values =
r at data$walker,  fun=function(x){mean(as.numeric(x)) } )


I am sorry for your head.

Best,
Robert

# This is the command I use to add points but for some reason, the
# values are not added (strictly speaking, only one value is added).
# Can someone point out what I'm doing wrong?
rst.p <- pointsToRaster(raster = rst,
       xy = r,
       values = r at data$walker)
rst.p
+        xy = r,
+        values = r at data$walker)

        
On Tue, Apr 13, 2010 at 4:45 AM, Roman Lu?trik <roman.lustrik at gmail.com> wrote: