buffer computes buffers regions from spatial objects belonging to the following classes:
SpatialPoints (all pixels located within a specified distance of a point take the value one)
SpatialPointsDataFrame with one column (this column is considered to be a factor, and the buffer is computed for each level of this factor)
SpatialLines to compute buffers from lines.
SpatialPolygons to compute buffers from polygons.
buffer(xy, x, dist)
Arguments
xy: an object of class SpatialPoints, SpatialPointsDataFrame with one column (a factor considered to be the identity of the points), SpatialLines, or SpatialPolygons.
x: an object inheriting the class SpatialPixels with the same attributes (resolution, size) as those desired for the output.
SpatialPixelsDataFrame-class for additionnal information on objects of class SpatialPixelsDataFrame.
Examples
data(lynxjura)# locs is the SpatialPointsDataFrame containing the# locations of lynx indices in the Jura mountainslocs <- lynxjura$locs
head(locs)## just for the sake of illustration: sample 100 pointssuppressWarnings(RNGversion("3.5.0"))set.seed(233)locs <- locs[sample(1:nrow(locs),100),]# sa is the SpatialPixelsDataFrame object containing# maps of the study areasa <- lynxjura$map
# Buffer of 2000 m from all pointsbu <- buffer(locs, sa,2000)image(bu)# displays all the pixels of the study area within 2000 m# of a point, for each type of indices (see ?lynxjura)buani <- buffer(locs[,2], sa,2000)buani
par(mar=c(0,0,2,0))opar<-par(mfrow=c(3,4))lapply(1:11,function(i){ image(buani[,i]) title(main = names(slot(buani,"data"))[i])})par(opar)## buffer from a polygonsa2 <- sa[,4]sa2[[1]][sa2[[1]]<5000]<-NAimage(sa2)## gets the contour linegc <- getcontour(sa2)plot(gc, add=TRUE)## a buffer of 2000 metresimage(buffer(gc, sa,2000))plot(gc, add=TRUE)