This script generates potential benchmarks, as well as upstream and downstream polygons based on the BUILDER output.
The first step is to locate catchments layer and specify the directory where BUILDER output were saved.
These polygons are then used to assess dendritic connectivity by clipping the stream network to each polygon and analyzing how water flows within its boundaries.
Generate potential benchmarks, upstream and downstream polygons from catchments using BUILDER output files
Function fetch_builder_output allow to read Builder output tables that uses column format. The output can then be passed to dissolve_catchment_from_table to generate polygons using enumerated ‘CATCHNUM’. fetch_builder_output needs the following:
out_dir: Point to a directory that contains Builder output
type: Indicate which file to read. Type can be ‘BENCHMARKS’, ‘UPSTREAM’ or ‘DOWNSTREAM’. Default is ‘BENCHMARKS’.
# Load required librarieslibrary(sf)library(dplyr)library(tidyr)library(utils)library(ggplot2)library(RColorBrewer)library(here)# --------------------------------------# SET PARAMS --------------------# --------------------------------------# Set working directorydirpath <-here(".")# Source BEACONs functionssource(file.path(dirpath,"R/spatial.R"))source(file.path(dirpath,"R/builder.R"))source(file.path(dirpath,"R/utils.R"))# Folder path to the benchmarkbuilder executablebuilder_path <-here("builder")# Set Builder output path (create the folder structure if missing)builder_dir <-file.path(dirpath, "output/Builder_output")if (!dir.exists(builder_dir)) {dir.create(builder_dir)}# Create the folder structure to receive output polygonsout_dir <-file.path(dirpath, "output/shp_output")if (!dir.exists(out_dir)) {dir.create(out_dir, recursive =TRUE)}# Prefix given to identify unique conservation areascolName <-"PB"# --------------------------------------#--RUN# --------------------------------------# Use conservation areas as reserve seedscatchments <-st_read(file.path(dirpath,"data/catchments_sample.shp"))
Reading layer `catchments_sample' from data source
`E:\MelinaStuff\BEACONs\git\R_tools_public\data\catchments_sample.shp'
using driver `ESRI Shapefile'
Simple feature collection with 108 features and 15 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: -2073549 ymin: 752749.6 xmax: -1946333 ymax: 861999.6
Projected CRS: NAD_1983_Albers