Skip to contents

Extracts data from raster covariate layers for modelling.

Usage

extract_covariates(
  covariates,
  presences = NULL,
  absences = NULL,
  presences_and_absences = NULL
)

Arguments

covariates

SpatRaster object of one or more layers.

presences

data.frame or tibble of presence locations contaning longitude and latitude as variables x and y.

absences

data.frame or tibble of absence or background locations contaning longitude and latitude as variables x and y.

presences_and_absences

data.frame or tibble of presence presence and absence locations containing longitude and latitude as variables x and y.

Value

A tibble containing values variables presence and each of the covariate layers at each location.

Details

extract_covariates will run correctly with either presences only, presences and absences, or presences_and_absences only. (If all three are included it will ignore the last one).

Author

Gerry Ryan

Examples


library(terra)
#> terra 1.7.83

cov1 <- example_raster(
 seed = -44,
 layername = "cov1"
)
cov2 <- example_raster(
 seed = 15.3,
 layername = "cov2"
)

covs <- c(cov1, cov2)


presences <- example_vector(seed = 68) %>%
 as.data.frame(geom = "xy")
absences <- example_vector(seed = 9.6) %>%
 as.data.frame(geom = "xy")

extract_covariates(
 covariates = covs,
 presences = presences,
 absences = absences
)
#> # A tibble: 20 × 3
#>     cov1  cov2 presence
#>    <dbl> <dbl>    <dbl>
#>  1 0.345 0.799        1
#>  2 2.92  0.477        1
#>  3 0.200 2.06         1
#>  4 0.172 0.313        1
#>  5 1.06  2.12         1
#>  6 1.41  0.265        1
#>  7 2.40  0.153        1
#>  8 1.70  4.30         1
#>  9 0.230 4.26         1
#> 10 1.70  4.30         1
#> 11 0.483 1.39         0
#> 12 0.487 0.341        0
#> 13 0.563 4.11         0
#> 14 1.31  2.08         0
#> 15 1.90  3.51         0
#> 16 1.70  4.30         0
#> 17 1.04  1.60         0
#> 18 1.55  0.630        0
#> 19 0.487 0.717        0
#> 20 4.01  4.72         0