View source: R/BackgroundSamplingFunctions.R
mSampling2D | R Documentation |
Samples in 2D at resolution of raster
mSampling2D(occs, rasterTemplate, mShp, verbose = TRUE)
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 |
|
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.
A data.frame
with 2D coordinates of points
for background sampling.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.