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
<- "path/to/BEACONs_R_tools"
dirpath
set(dirpath)
source("./R/hydrology.R")
#Set access path
<- file.path(dirpath, "data/reserves.shp")
reserves <- file.path(dirpath, "data/streams.shp")
streams
<- "reserve"
colName
#Create output folder
<- file.path(dirpath, "shp_output")
out_dir if(!dir.exists(out_dir)){
dir.create(out_dir)
}
# Set if DCI and LWDCI should be added
<- TRUE
addDCI <- TRUE
addLWDCI
# --------------------------------------
#--RUN
# --------------------------------------
# Initialize sf objects
<- st_read(reserves)
reserves_sf <- st_read(streams)
streams_sf
if(addDCI){
<- reserves_sf %>%
reserves_sf mutate(dci = sapply(1:nrow(reserves_sf), function(i) {
<- reserves_sf[i, ]
i calc_dci(i, streams_sf, col_name = colName)
}))
}if(addLWDCI){
<- reserves_sf %>%
reserves_sf mutate(lwdci = sapply(1:nrow(reserves_sf), function(j) {
<- reserves_sf[j, ]
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)