15.2 Preprocessing

The next step is to compute variables

  • modeling and predictive mapping
  • aligning the Non-metric multidimensional scaling (NMDS) axes with the main gradient in the study area, altitude and humidity, respectively

15.2.1 Bridges to GIS Software

qgisprocess::qgis_show_help("saga:sagawetnessindex")
#> Saga wetness index (saga:sagawetnessindex)
#> ...
#> ----------------
#> Arguments
#> ----------------
#> 
#> DEM: Elevation
#>  Argument type:  raster
#>  Acceptable values:
#>      - Path to a raster layer
#> ...
#> SLOPE_TYPE: Type of Slope
#>  Argument type:  enum
#>  Available values:
#>      - 0: [0] local slope
#>      - 1: [1] catchment slope
#> ...
#> AREA: Catchment area
#>  Argument type:  rasterDestination
#>  Acceptable values:
#>      - Path for new raster layer
#>... 
#> ----------------
#> Outputs
#> ----------------
#> 
#> AREA: <outputRaster>
#>  Catchment area
#> SLOPE: <outputRaster>
#>  Catchment slope
#> ...
# environmental predictors: catchment slope and catchment area
ep = qgisprocess::qgis_run_algorithm(
  alg = "saga:sagawetnessindex",
  DEM = dem,
  SLOPE_TYPE = 1, 
  SLOPE = tempfile(fileext = ".sdat"),
  AREA = tempfile(fileext = ".sdat"),
  .quiet = TRUE)
# read in catchment area and catchment slope
ep = ep[c("AREA", "SLOPE")] |>
  unlist() |>
  terra::rast()
names(ep) = c("carea", "cslope") # assign proper names 
terra::origin(ep) = terra::origin(dem) # make sure rasters have the same origin
ep = c(dem, ndvi, ep) # add dem and ndvi to the multilayer SpatRaster object
ep$carea = log10(ep$carea) #since data was skewed right

15.2.2 Site Locations

# this raster was made available for convenience
ep = terra::rast(system.file("raster/ep.tif", package = "spDataLarge"))
# terra::extract adds automatically a for our purposes unnecessary ID column
ep_rp = terra::extract(ep, random_points) |>
  select(-ID)
random_points = cbind(random_points, ep_rp)

str(ep_rp, give.attr = FALSE)
## 'data.frame':    100 obs. of  4 variables:
##  $ dem   : num  272 280 283 292 299 299 304 308 310 310 ...
##  $ ndvi  : num  -0.36 -0.349 -0.34 -0.364 -0.336 ...
##  $ carea : num  5.79 4.85 5.73 3.79 3.85 ...
##  $ cslope: num  0.337 0.2275 0.41 0.0999 0.3691 ...