xyValues(object, xy, ...)
n*2
matrix or dataframe with the first column having the x values, and the second column has the y values.
It can also be a SpatialPoints*
object, or a vector of length method
. If method='simple'
(the default), values for the cell a point falls in are returned. The
alternative is method='bilinear'
, in which case the returned values are interpolated from the values of the four nearest raster cells.
2) buffer
. The radius of a buffer around each point for which to extract cell values.
It can be a single value, or a vector of the length of the number of points.
If the data are not projected (latitude/longitude), the unit should be meters. Otherwise it should be in map-units (typically also meters).
3) fun
. Only useful when non-zero buffers are used. The values of all the cells are summarized with the function. The function should
take a single numeric vector as argument and return a single values (e.g. mean, min or max).
4) na.rm
. Only useful when fun
is supplied. If na.rm=TRUE
(the default value), NA values are removed before fun is applied.cellValues
, polygonValues
, focalValues
r <- raster()
r[] <- 1:ncell(r)
xy <- cbind(-50, seq(-80, 80, by=20))
xyValues(r, xy)
xyValues(r, xy, method='bilinear')
# examples with a buffer
xyValues(r, xy[1:3,], buffer=100000)
xyValues(r, xy[1:3,], buffer=100000, fun=mean)
## illustrating the varying size of a buffer (expressed in meters) on a longitude/latitude raster
z <- xyValues(r, xy, buffer=1000000)
s <- raster(r)
for (i in 1:length(z)) { s[z[[i]]] <- i }
## compare with raster that is not longitude/latitude
projection(r) <- NA
xy[,1] <- 50
z <- xyValues(r, xy, buffer=8)
for (i in 1:length(z)) { s[z[[i]]] <- i }
plot(s)
# library(maptools)
# data(wrld_simpl)
# plot(wrld_simpl, add=TRUE)
Run the code above in your browser using DataLab