Reduces number of occurrences to resolution of input raster

downsample(occs, rasterTemplate, verbose = TRUE)

Arguments

occs

A data.frame 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 the resolution at which occs should be downsampled.

verbose

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

Value

A data.frame with two columns named "longitude" and "latitude" or with names that were used when coercing input data into this format.

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 <- as.data.frame(cbind(longitude,latitude))

# Here's the function
result <- downsample(occs = occurrences, rasterTemplate = r)
#> Using longitude and latitude
#>  as x and y coordinates, respectively.