项目作者: jsta

项目描述 :
Morphology analysis of stream networks 🍃
高级语言: R
项目地址: git://github.com/jsta/streamnet.git
创建时间: 2017-09-25T19:21:43Z
项目社区:https://github.com/jsta/streamnet

开源协议:

下载


streamnet

CRAN
status
Lifecycle:
experimental
Travis-CI Build
Status
DOI

Morphology analysis of stream networks

Installation

You can install streamnet from github with:

  1. # install.packages("devtools")
  2. 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.

Usage

Calculate morphology metrics

  1. library(sf)
  2. library(nhdR)
  3. library(streamnet)
  4. library(ggplot2)
  5. library(raster)
  1. data(nhd_sub_lines)
  2. data(nhd_sub_lakes)
  3. outlet_reach <- terminal_reaches(network = nhd_sub_lines,
  4. approve_all_dl = TRUE, quiet = TRUE)
  5. outlet_point <- st_cast(st_line_sample(outlet_reach, sample = 1), "POINT")
  6. ggplot() +
  7. geom_sf(data = nhd_sub_lines) +
  8. geom_sf(data = outlet_point, aes(color = "red")) +
  9. scale_color_manual(labels = "outlet", values = "red") +
  10. labs(colour = "") + theme_minimal()
  11. calc_metrics(nhd_sub_lines, nhd_sub_lakes)

Simplify stream networks

  1. data(nhd_sub_lines)
  2. # Combine(dissolve) adjacent reaches with no junctions
  3. nhd_sub_simple <- simplify_network(nhd_sub_lines)
  4. avg_link_length(nhd_sub_simple)
  5. #> 2444.693 [m]
  6. avg_link_length(nhd_sub_lines)
  7. #> 1312.988 [m]

Round-trip igraph and sf lines

  1. tree <- create_reversed_tree(15)
  2. class(tree)
  3. #> [1] "igraph"
  4. plot(tree)

  1. tree_sf <- igraph2sf(tree)
  2. plot(tree_sf)

Create synthetic stream networks

  1. # Diffusion limited aggregation
  2. dt <- sim_dla()
  3. viz_dla(dt, which.max(dt))

  1. # Generate from a binary raster
  2. foo <- matrix(0, ncol = 9, nrow = 9)
  3. foo[1:4,3] <- 1
  4. foo[5,4] <- 1
  5. foo[6:9,5] <- 1
  6. foo <- raster(foo, xmn = 1, xmx = 9, ymn = 1, ymx = 9)
  7. origin <- which.min(apply(
  8. which(as.matrix(flip(foo, "y")) == 1, arr.ind = TRUE), 1, sum))
  9. res <- raster2network(foo, origin)
  10. par(mfrow = c(1, 2))
  11. plot(foo)
  12. plot(foo); plot(res, add = TRUE)