R package for stream network analysis, focused on connectivity
metrics, order calculation (such as Link Magnitude), and spatial
manipulation integrated with terra, igraph,
and sf.
# Development version via GitHub
# install.packages("devtools")
devtools::install_github("diogosbr/RGDrivers")This example uses a small set of fictional line reaches included in the package.
library(RGDrivers)
library(terra)
# 1. Load sample data
network <- vect(system.file("extdata/rede_exemplo.gpkg", package = "RGDrivers"))
# 2. Create graph
g <- create_network_graph(network, col_id = "id", col_downstream = "jus")
# 3. Calculate Link Magnitude
lm <- calculate_link_magnitude(g)
# 4. Add to data.frame
df <- as.data.frame(network)
df$link_mag <- lm[as.character(df$id)]
df <- calculate_dlink(df, col_id = "id", col_downstream = "jus", col_order = "link_mag")
# 5. Assign back to the vector
network$link_mag <- df$link_mag
network$D_LINK <- df$D_LINK
# 6. Plot the result
plot(network, col = network$link_mag, main = "Link Magnitude")create_network_graph() – creates a graph from reach
datacalculate_link_magnitude() – calculates the Shreve
ordercalculate_dlink() – obtains the downstream reach
orderwrite_network_with_orders() – saves a vector with
orderscreate_stream_network() – creates a graph directly from
sf reachescalculate_outlet_distance() – accumulated distance to
the outletThis package is licensed under the terms of the MIT license.