BEACONs Spatial R Functions
dissolve_catchments_from_table()
The dissolve_catchments_from_table()
function takes lists of catchments from a table where each column represents a polygon to be created, and dissolves the catchments into a single polygon feature. Optionally the function can adds area in km2, and area-weighted intactness.
Usage
dissolve_catchments_from_table(
catchments_sf,
input_table,out_feature_id=NULL,
calc_area = FALSE,
intactness_id = NULL,
dissolve_list = c(),
drop_table = NULL
)
Arguments
the function need the following:
catchments_sf: sf object of the catchments dataset with unique identifier column: CATCHNUM.
input_table: Data frame where column names are polygon names and rows are catchments making up each polygon. e.g. output from
get_upstream_catchments()
(upstream_downstream.qmd).out_feature_id: String representing the output column name holding the polygon unique identifiers.
calc_area: If TRUE, an area_km2 column is added to the output containing the polygon area.
intactness_id: Optional string identifying an intactness column (values between 0 and 1) in catchments_sf. If provided, used to calculate the area weighted intactness (AWI) of the dissolved polygons.
dissolve_list: Vector of columns in to include in the output. Defaults to colnames(input_table). Can also dissolve multiple columns from together by combining column names with (e.g. PB_0001__PB_0002).
drop_table: A table in the same format listing catchments to be dropped from the dissolve area.
📤 Output
A sf object of polygons with unique identifier column .
Details
The is in the form exported from the beaconsbuilder package, where each column lists catchment ids, and each column name represents the unique identifier of the output polygon.
This function is used to create conservation area polygons using tables created by the beaconsbuilder package, and upstream polygons using tables created by [get_upstream_catchments()].
The optional parameter can be used to filter the column names in that will be dissolved. The can also contain combinations of column name separated by , in this case the output polygon will dissolve the combined area of catchments from all columns in the string. For example, the string “PA1__PA2” in the will output a polygon representing the dissolved area of all catchments listed in the PA1 and PA2 columns of .
The main application of is to remove conservation area catchments from the dissolved area when dissolving upstream catchments tables. See vignette(‘overview’) for an example.
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)