knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/", eval = FALSE )
Morphology analysis of stream networks
You can install streamnet from github with:
# install.packages("devtools") devtools::install_github("jsta/streamnet")
In addition, many functions require a system installation of GRASS 7 along with the v.stream.order extension.
There is a helper function to install v.stream.order
at streamnet:::install_grass_extensions
.
Sys.setenv(GRASS_VERBOSE = 0)
library(sf) library(nhdR) library(streamnet) library(ggplot2) library(raster)
data(nhd_sub_lines) data(nhd_sub_lakes) outlet_reach <- terminal_reaches(network = nhd_sub_lines, approve_all_dl = TRUE, quiet = TRUE) outlet_point <- st_cast(st_line_sample(outlet_reach, sample = 1), "POINT") ggplot() + geom_sf(data = nhd_sub_lines) + geom_sf(data = outlet_point, aes(color = "red")) + scale_color_manual(labels = "outlet", values = "red") + labs(colour = "") + theme_minimal() calc_metrics(nhd_sub_lines, nhd_sub_lakes)
data(nhd_sub_lines) # Combine(dissolve) adjacent reaches with no junctions nhd_sub_simple <- simplify_network(nhd_sub_lines) avg_link_length(nhd_sub_simple) avg_link_length(nhd_sub_lines)
tree <- create_reversed_tree(15) class(tree) plot(tree) tree_sf <- igraph2sf(tree) plot(tree_sf)
# Diffusion limited aggregation dt <- sim_dla() viz_dla(dt, which.max(dt))
knitr::include_graphics("man/figures/show_dla.png")
# Generate from a binary raster foo <- matrix(0, ncol = 9, nrow = 9) foo[1:4,3] <- 1 foo[5,4] <- 1 foo[6:9,5] <- 1 foo <- raster(foo, xmn = 1, xmx = 9, ymn = 1, ymx = 9) origin <- which.min(apply( which(as.matrix(flip(foo, "y")) == 1, arr.ind = TRUE), 1, sum)) res <- raster2network(foo, origin) par(mfrow = c(1, 2)) plot(foo) plot(foo); plot(res, add = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.