SpaDES (version 1.1.4)

cir: Identify pixels in a circle around a SpatialPoints* object.

Description

identify the pixels and coordinates that are at a (set of) buffer distance(s) of the SpatialPoints* objects. This can be used for agents.

Usage

cir(spatialPoints, radii, raster, simplify = TRUE)

Arguments

spatialPoints
SpatialPoints* object around which to make circles .
radii
vector of radii that has same length as spatialPoints
raster
Raster on which the circles are built.
simplify
logical. If TRUE, then all duplicate pixels are removed. This means that some x, y combinations will disappear

Value

  • A data.table with 5 columns, ids, pixelIDs, rasterVal, x, y. The x and y indicate the coordinates of each unique pixel of the circle around each individual.

Examples

Run this code
library(raster)
library(sp)

Ras <- raster(extent(0, 15, 0, 15), res = 1)
Ras <- randomPolygons(Ras, numTypes = 4, speedup = 1, p = 0.3)
N <- 2
caribou <- SpatialPoints(coords = cbind(x = stats::runif(N, xmin(Ras), xmax(Ras)),
                                        y = stats::runif(N, xmin(Ras), xmax(Ras))))
cirs <- cir(caribou, rep(3, length(caribou)), Ras, simplify = TRUE)
cirsSP <- SpatialPoints(coords = cirs[, list(x, y)])
cirsRas <- raster(Ras)
cirsRas[] <- 0
cirsRas[cirs[, pixIDs]] <- 1
Plot(Ras, new = TRUE)
Plot(cirsRas, addTo = "Ras", cols = c("transparent", "#00000055"))
Plot(caribou, addTo = "Ras")
Plot(cirsSP, addTo = "Ras")

Run the code above in your browser using DataLab