Assessing hydrology on reserves

Intro

Both functions need the following:

  • reserves: Point to a polygon sf object
  • streams: Point to an stream_sf object. The provided streams need to have information on BASIN.
  • col_name: Column name holding the unique ID of the pas_sf. Default is network.
  • buffer_width: Width of buffer to apply to stream segments. Defaults to 0.1. Used to ensure adjacent stream segments are connected during analysis.

To estimate DCI index within a reserve (e.g., potential benchmarks, protected area), the user needs to provide the stream network layers that uses the same coordinate reference system (CRS) as the reserve layer..

# Load libraries
library(sf)
library(dplyr)

# --------------------------------------
# SET PARAMS  --------------------
# --------------------------------------
# Set working directory
dirpath <- "path/to/BEACONs_R_tools"

set(dirpath)
source("./R/hydrology.R")

#Set access path 
reserves <- file.path(dirpath, "data/reserves.shp")
streams <- file.path(dirpath, "data/streams.shp")

colName <- "reserve"

#Create output folder
out_dir <- file.path(dirpath, "shp_output")
if(!dir.exists(out_dir)){
  dir.create(out_dir)
}

# Set if DCI and LWDCI should be added
addDCI <- TRUE
addLWDCI <- TRUE


# --------------------------------------
#--RUN
# --------------------------------------
# Initialize sf objects
reserves_sf <- st_read(reserves)
streams_sf <- st_read(streams)

if(addDCI){
  reserves_sf <- reserves_sf %>%
  mutate(dci = sapply(1:nrow(reserves_sf), function(i) {
    i <- reserves_sf[i, ]
    calc_dci(i, streams_sf, col_name = colName) 
  }))
}
if(addLWDCI){
  reserves_sf <- reserves_sf %>%
  mutate(lwdci = sapply(1:nrow(reserves_sf), function(j) {
    j <- reserves_sf[j, ]
    calc_lwdci(j, streams_sf, col_name = colName) 
  }))
}

#Save results
write_sf(reserves_sf, dsn=file.path(out_dir, "reserves_dci.shp"), append = FALSE)