BEACONs Hydrology R Functions
get_upstream_catchments()
andget_downstream_catchemnts()
The get_upstream_catchments()
and get_downstream_catchemnts()
functions return upstream or downstream catchments for a set of input polygons as a table, with conservation_area_id as the unique id.
Usage
get_upstream_catchments(
conservation_area_sf,
conservation_area_id,
catchments_sf
)
get_downstream_catchments(
conservation_area_sf,
conservation_area_id,
catchments_sf )
Arguments
Both functions need the following:
conservation_area_sf: sf object of protected area polygons.
conservation_area_id: String matching the unique identifier column in .
catchments_sf: sf object of the catchments dataset with unique identifier column: CATCHNUM .
📤 Output
A tibble where each column name is a unique polygon id, and each row is a catchment making up the upstream or downstream area for the polygon. Blank rows are filled with NA. CATCHNUMs are returned as integers.
Details
The upstream and downstream regions of a targeted polygons (i.e. conservation area) can inform on potential sources of external vulnerability due to water-mediated influences. For instance, assessing a conservation area’s vulnerability may involve examining upstream human disturbances—such as pollutant inputs or water diversions (e.g., dams)—while looking at downstream areas of a disturbed regions (i.e. mine) can provide insight into the potential spread of ecological impacts originating from the region.
Examples
Running the examples
The example below allow to identify upstream and downstream areas and save them as layers.
Download and unzip BEACONs R Tools
Run the examples below.
# Load libraries
library(sf)
library(dplyr)
# Set working directory
setwd("your/path/to/downloads/folder")
source("./R/hydrology.R")
source("./R/spatial.R")
# --------------------------------------
# SET PARAMS --------------------
# --------------------------------------
<- getwd()
dirpath
#Set access path
<- file.path(dirpath, "data/reserves_sample.shp")
reserves <- file.path(dirpath, "data/catchments_sample.shp")
catchments
<- "reserve"
colName
#Create output folder
<- file.path(dirpath, "shp_output")
out_dir if(!dir.exists(out_dir)){
dir.create(out_dir)
}
# --------------------------------------
#--RUN
# --------------------------------------
# Initialize sf objects
<- st_read(reserves)
reserves_sf <- st_read(catchments)
catchments_sf
<- get_upstream_catchments(reserves_sf, colName, catchments_sf)
upstream_tbl
# Turn the tibble into sf object
<- dissolve_catchments_from_table(catchments_sf, upstream_tbl, colName)
upstream_sf
#Plot results
plot(st_geometry(catchments_sf), col = "lightblue", main = "Upstream Catchments Example")
plot(st_geometry(upstream_sf), col = "green", add = TRUE)
plot(st_geometry(reserves_sf), col = "red", add = TRUE)