Samples in 2D at resolution of raster

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 SpatRaster object to serve as a template for generating background sampling coordinates.

mShp

A shapefile defining the area from which background points should be sampled.

verbose

logical. Switching to FALSE mutes message describing which columns in occs are interpreted as x and y coordinates.

Value

A data.frame with 2D coordinates of points for background sampling.

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.

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)
#> Using longitude and latitude
#>  as x and y coordinates, respectively.