| Title: | Calculate the Dendritic Connectivity Index in River Networks |
|---|---|
| Description: | Calculate and analyze ecological connectivity across the watercourse of river networks using the Dendritic Connectivity Index. |
| Authors: | Alex Arkilanian [aut, cre] (ORCID: <https://orcid.org/0000-0002-5427-2867>) |
| Maintainer: | Alex Arkilanian <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.3 |
| Built: | 2026-05-17 09:53:11 UTC |
| Source: | https://github.com/aarkilanian/dci |
river_net ObjectCalculates the potamodromous and diadromous forms of the Dendritic
Connectivity Index (DCI) for a river_net object.
calculate_dci( net, form, pass = NULL, weight = NULL, threshold = NULL, parallel = FALSE, quiet = FALSE )calculate_dci( net, form, pass = NULL, weight = NULL, threshold = NULL, parallel = FALSE, quiet = FALSE )
net |
A |
form |
A string specifying the DCI form to calculate. Options are: "pot" for potamodromous or "dia" for diadromous. |
pass |
The name of a column in the nodes table of |
weight |
The name of a column in the edges table of |
threshold |
Optional numeric value specifying a dispersal limit in map
units. If |
parallel |
Logical. If |
quiet |
Logical. If |
Passability values are probabilities between 0 and 1, where 0 indicates a fully impassable barrier and 1 indicates full passability. If values in the specified passability column fall outside this range, they will be normalized.
Weighting values should also be probabilities between 0 and 1. River segments
with weights of 0 or NA will be excluded from the DCI calculation.
Upon successful calculation, the global DCI value for the river network will
be printed to the console unless quiet = TRUE.
An sf object of the river network with new columns specifying
segmental DCI values and relative DCI values. These are each segment's
contribution to the global DCI score which is printed. The relative values
are simply those values normalized.
# For the potamodromous DCI res <- calculate_dci(net = yamaska_net, form = "pot", pass = "pass_1", weight = "weight")# For the potamodromous DCI res <- calculate_dci(net = yamaska_net, form = "pot", pass = "pass_1", weight = "weight")
Identifies and optionally corrects features in a river network that violate a strictly dendritic topology.
enforce_dendritic(rivers, correct = TRUE, quiet = FALSE, max_iter = 10)enforce_dendritic(rivers, correct = TRUE, quiet = FALSE, max_iter = 10)
rivers |
A |
correct |
Logical. If |
quiet |
Logical. If |
max_iter |
An integer indicating the maximum number of correction iterations to run. As some topological errors are corrected new ones can can arise requiring multiple passes. In some cases, an automated correction choice can lead to a recursive correction that eliminates most rivers. In this case, some manual corrections may help avoid this. |
In a dendritic network, two upstream rivers converge into a single downstream river at each confluence. This function can enforce this dendritic topology in a river network by detecting (and optionally correcting) two types of topological errors: (1) divergences, where a single river splits into multiple downstream branches (commonly forming loops or braided channels), and (2) complex confluences, where more than two upstream rivers meet at a single point.
If errors are being corrected manually, rerun this function again until no errors remain as correcting divergences can lead to other topological errors that need to be corrected
If correct = FALSE, returns a sf object with the columns
"divergent" and "complex" indicating topological errors. These columns
contain integer identifiers indicating which features are part of the
same divergent or complex structure. If correct = TRUE, returns a
rivers object with the topological issues corrected.
# Import rivers rivers_in <- import_rivers(yamaska_rivers, quiet = TRUE) # Correct errors automatically rivers_cor <- enforce_dendritic(rivers_in, correct = TRUE) # Return highlighted topological errors for manual correction rivers_uncor <- enforce_dendritic(rivers_in, correct = FALSE) # For large river networks it may be better to specify a smaller number of # correction sweeps. rivers_cor <- enforce_dendritic(rivers_in, correct = TRUE, max_iter = 3)# Import rivers rivers_in <- import_rivers(yamaska_rivers, quiet = TRUE) # Correct errors automatically rivers_cor <- enforce_dendritic(rivers_in, correct = TRUE) # Return highlighted topological errors for manual correction rivers_uncor <- enforce_dendritic(rivers_in, correct = FALSE) # For large river networks it may be better to specify a smaller number of # correction sweeps. rivers_cor <- enforce_dendritic(rivers_in, correct = TRUE, max_iter = 3)
Exports the output of calculate_dci() as a spatial object with DCI values joined
to the relevant features in the river network.
export_dci(net, results, type = "rivers", relative = FALSE, quiet = TRUE)export_dci(net, results, type = "rivers", relative = FALSE, quiet = TRUE)
net |
A |
results |
A |
type |
A character string specifying which component of the river network
the results should be exported for. Valid options are |
relative |
A logical value indicating whether relative DCI values should
be returned in addition to raw values. Defaults to |
quiet |
Logical. If |
An sf object containing the corresponding DCI results joined
to the selected network component. If multiple results are supplied, result
columns are appended by a number corresponding to the index of the
associated results.
res_pot <- calculate_dci(net = yamaska_net, form = "pot", pass = "pass_1", quiet = TRUE) res_dia <- calculate_dci(net = yamaska_net, form = "dia", pass = "pass_1", quiet = TRUE) # Export segment-level potamodromous DCI results to rivers riv_results <- export_dci(net = yamaska_net, results = res_pot, type = "rivers") # Can also be run quietly to keep from plotting results riv_results <- export_dci(net = yamaska_net, results = res_pot, type = "rivers", quiet = TRUE) # Results can also be exported to barrier points bar_results <- export_dci(net = yamaska_net, results = res_pot, type = "bars") # If multiple results are calculated these can be combined together all_res <- export_dci(net = yamaska_net, results = list(res_pot, res_dia), type = "rivers")res_pot <- calculate_dci(net = yamaska_net, form = "pot", pass = "pass_1", quiet = TRUE) res_dia <- calculate_dci(net = yamaska_net, form = "dia", pass = "pass_1", quiet = TRUE) # Export segment-level potamodromous DCI results to rivers riv_results <- export_dci(net = yamaska_net, results = res_pot, type = "rivers") # Can also be run quietly to keep from plotting results riv_results <- export_dci(net = yamaska_net, results = res_pot, type = "rivers", quiet = TRUE) # Results can also be exported to barrier points bar_results <- export_dci(net = yamaska_net, results = res_pot, type = "bars") # If multiple results are calculated these can be combined together all_res <- export_dci(net = yamaska_net, results = list(res_pot, res_dia), type = "rivers")
Reads and prepares geospatial point data for use with river_net().
import_points(pts, type)import_points(pts, type)
pts |
A character string specifying the path to a shapefile of points,
or an |
type |
A character string indicating the type of points. Must be one of:
|
An object of class barriers or outlet depending on type,
prepared for use with river_net().
import_points(yamaska_barriers, type = "bars") import_points(yamaska_outlet, type = "out")import_points(yamaska_barriers, type = "bars") import_points(yamaska_outlet, type = "out")
Reads and prepares geospatial river line data for use in river_net().
Only the largest fully connected component of the network is retained;
river lines that are part of disconnected secondary networks are discarded.
import_rivers(rivers, quiet = FALSE)import_rivers(rivers, quiet = FALSE)
rivers |
A character string specifying the path to a shapefile of river lines,
or an |
quiet |
Logical. If |
An object of class rivers, suitable for use with enforce_dendritic()
or as input to river_net().
rivers_in <- import_rivers(yamaska_rivers) # This can also be done quietly to omit plotting river lines after importing rivers_in <- import_rivers(yamaska_rivers, quiet = TRUE)rivers_in <- import_rivers(yamaska_rivers) # This can also be done quietly to omit plotting river lines after importing rivers_in <- import_rivers(yamaska_rivers, quiet = TRUE)
river_net ObjectConstructs a river_net object, a geospatial network structure built on top
of the sfnetworks::sfnetwork() class. This object integrates river lines,
barriers and outlets allowing for connectivity analyses with
calculate_dci() or other network tools.
river_net( rivers, barriers, outlet, check = TRUE, tolerance = NULL, max_iter = 10 )river_net( rivers, barriers, outlet, check = TRUE, tolerance = NULL, max_iter = 10 )
rivers |
A |
barriers |
A |
outlet |
An |
check |
Logical. If |
tolerance |
A numeric value specifying the snapping distance
(in map units) to align points to the river network. Defaults to |
max_iter |
An integer indicating the maximum number of correction iterations to run. As some topological errors are corrected new ones can can arise requiring multiple passes. In some cases, an automated correction choice can lead to a recursive correction that eliminates most rivers. In this case, some manual corrections may help avoid this. |
An object of class river_net representing the river network formed from the provided spatial inputs.
riv_in <- import_rivers(yamaska_rivers, quiet = TRUE) bar_in <- import_points(yamaska_barriers, type = "bars") out_in <- import_points(yamaska_outlet, type = "out") # For large river networks it may be better to specify a smaller number of # correction sweeps. yam_net <- river_net(rivers = riv_in, barriers = bar_in, outlet = out_in, max_iter = 3)riv_in <- import_rivers(yamaska_rivers, quiet = TRUE) bar_in <- import_points(yamaska_barriers, type = "bars") out_in <- import_points(yamaska_outlet, type = "out") # For large river networks it may be better to specify a smaller number of # correction sweeps. yam_net <- river_net(rivers = riv_in, barriers = bar_in, outlet = out_in, max_iter = 3)
An sf object of the POINT geometries that make up imagined barriers on the
Yamaska watershed of Southern Québec. Features are projected to CRS:32198.
yamaska_barriersyamaska_barriers
An sf object with 620 LINESTRING features:
the passability of nodes in the network from 0 (impassable) to 1
the binary passability of nodes in the network, 0 if a barrier and 1 otherwise
the geometry list column of river POINT features
A spatial river_net object extending the tidygraph representation of
spatial graphs. Nodes represent confluences, river endpoints, barriers, and
the outlet. Edges represent stream reaches. Spatial features are projected to
EPSG:32198.
yamaska_netyamaska_net
A river_net object with:
the geometry list column of the node point features
the passability of nodes in the network from 0 (impassable) to 1
the binary passability of nodes in the network, 0 if a barrier and 1 otherwise
the type of the node: topological, barrier, or outlet
the row index of the origin node of the edge feature
the row index of the destination node of the edge feature
a simulated weighting based on habitat quality of features
length of edge features in meters
unique river feature integer ID
the geometry list column of edge line features
https://www.donneesquebec.ca/recherche/dataset/grhq
https://www.donneesquebec.ca/recherche/dataset/structure
An sf object of the POINT geometry of the outlet of the Yamaska watershed
of Southern Québec. The feature is projected to CRS:32198.
yamaska_outletyamaska_outlet
An sf object with 1 POINT feature:
the geometry list column of the outlet POINT feature
https://www.donneesquebec.ca/recherche/dataset/grhq
https://www.donneesquebec.ca/recherche/dataset/structure
An sf object of the LINESTRING geometries that make up the rivers of the
Yamaska watershed of Southern Québec. The rivers make up the edges of the
yamaska_net object. Features are projected to CRS:32198.
yamaska_riversyamaska_rivers
An sf object with 620 features:
a simulated weighting based on habitat quality of features
length of edge features in meters
the geometry list column of edge line features
https://www.donneesquebec.ca/recherche/dataset/grhq
https://www.donneesquebec.ca/recherche/dataset/structure