BUILDER R Functions
fetch_builder_output()
The fetch_builder_output()
function reads and returns the appropriate output CSV file generated by the Builder tool, based on the specified type ("BENCHMARKS"
, "UPSTREAM"
, or "DOWNSTREAM"
).
The most recent matching file is selected if multiple are found. The file is returned as a tibble.
Usage
fetch_builder_output(builder_dir,
type = "BENCHMARKS"
)
Arguments
- builder_dir: Path to the Builder output directory.
- type: Type of output to retrieve. Must be one of
"BENCHMARKS"
,"UPSTREAM"
, or"DOWNSTREAM"
. Default is"BENCHMARKS"
.
📤 Output
A tibble of neighbouring pairs with columns CATCHNUM and neighbours.
Examples
Running the examples
Download and unzip BEACONs R Tools
Run the examples below.
# Load required libraries
library(dplyr)
library(utils)
library(sf)
library(ggplot2)
library(RColorBrewer)
# Set working directory
<- "path/to/BEACONs_R_Tools"
dirpath <- "path/to/builder/out_dir"
builder_outdir
setwd(dirpath)
source("./R/builder.R")
#Set access path catchments layer and initialize
<- st_read(file.path(dirpath,"data","catchments_sample.shp"))
catchments_sf
# Prefix given to identify unique conservation areas
<- "PB"
colName
# --------------------------------------
#--RUN
# --------------------------------------
# Map potential conservation areas generated by BUILDER
<- fetch_builder_output(builder_outdir, type = "BENCHMARKS")
out_tab
# Convert builder output tables to polygons
<- dissolve_catchments_from_table(catchments_sf = catchments_sf,
PBx_sf input_table = out_tab,
out_feature_id = colName)
# Pick random set of 12 to display
<- PBx_sf %>%
PBx_sample slice_sample(n = 12)
# Set color palette
<- nrow(PBx_sample)
n <- brewer.pal(min(n, 12), "Set3")
palette
# Plot catchments and conservation areas
ggplot() +
geom_sf(data = catchments_sf, fill = "grey90", color = "black", alpha = 0.3) +
geom_sf(data = PBx_sample, aes(fill = PB), color = "black", alpha = 0.7) +
scale_fill_manual(values = palette) +
labs(
title = "Distinct Potential Conservation Areas",
fill = "Conservation ID"
+
) theme_minimal()