mSampling2D {voluModel} | R Documentation |
2D background sampling
Description
Samples in 2D at resolution of raster
Usage
mSampling2D(occs, rasterTemplate, mShp, verbose = TRUE)
Arguments
occs |
A dataframe with at least two columns named "longitude" and "latitude", or that can be coerced into this format. |
rasterTemplate |
A |
mShp |
A shapefile defining the area from which background points should be sampled. |
verbose |
|
Details
This function is designed to sample background points
for distributional modeling in two dimensions. The returned
data.frame
contains all points from across the designated
background. It is up to the user to determine how to
appropriately sample from those background points.
Value
A data.frame
with 2D coordinates of points
for background sampling.
Examples
library(terra)
# Create sample raster
r <- rast(ncol=10, nrow=10)
values(r) <- 1:100
# Create test occurrences
set.seed(0)
longitude <- sample(ext(r)[1]:ext(r)[2],
size = 10, replace = FALSE)
set.seed(0)
latitude <- sample(ext(r)[3]:ext(r)[4],
size = 10, replace = FALSE)
occurrences <- data.frame(longitude,latitude)
# Generate background sampling buffer
buffPts <- vect(occurrences,
c("longitude", "latitude"))
crs(buffPts) <- crs(r)
mShp <- aggregate(buffer(buffPts, width = 1000000))
# Here's the function
result <- mSampling2D(occs = occurrences, rasterTemplate = r, mShp = mShp)