depthMatch: Match the depth values given in an occurrence dataset to the...

View source: R/depthMatch.R

depthMatchR Documentation

Match the depth values given in an occurrence dataset to the depth slice values of a user provided spatRaster stack

Description

assigns coordinates to depth slices given a user provided raster template. if any points are deeper than the lowest depth slice, they are assigned to the lowest depth slice.

Usage

depthMatch(occs, rasterTemplate)

Arguments

occs

dataframe of occurrence records with colnames "longitude," "latitude," and "depth." Depth values should be positive.

rasterTemplate

a spatRaster stack where the layer names correspond to the depth value, as a positive number

Details

rasterTemplate names and values in the depth column of occs should be positive. Points lower than the deepest depth slice are assigned to the deepest depth slice

Value

object of class dataframe, the same occs fed into the function but with the depth values adjusted to match the spatRaster stack depth slices

Examples

library(terra)
# Create test raster brick
r1 <- rast(ncol = 100, nrow = 100)
r2 <- rast(ncol = 100, nrow = 100)
r3 <- rast(ncol = 100, nrow = 100)
rbrick <- c(r1, r2, r3)
names(rbrick) <- c(1, 40, 90)

# Create test occurrences
set.seed(0)
longitude <- sample(ext(r1)[1]:ext(r1)[2], size = 10, replace = FALSE)
set.seed(0)
latitude <- sample(ext(r1)[3]:ext(r1)[4], size = 10, replace = FALSE)
set.seed(0)
depth <- sample(1:100, size = 10, replace = TRUE)
occs <- data.frame(longitude, latitude, depth)

# Here's the function
result <- depthMatch(occs = occs, rasterTemplate = rbrick)


voluModel documentation built on July 23, 2026, 5:07 p.m.