R/sbn_get_outlet.R

Defines functions sbn_get_outlet

Documented in sbn_get_outlet

#' Find river mouth node
#'
#' Find river mouth node from a directed graph.
#'
#' @param g a river network as an igraph object. Must be a downstream directed graph.
#'
#' @return An integer identifying the id of river mouth node.
#'
#' @importFrom igraph is.directed V adjacent_vertices
#'
#' @examples
#' g <- sbn_create(10, 0.7)
#' sbn_get_outlet(g)
#'
#' @export
sbn_get_outlet <- function(g){

  if (!igraph::is.directed(g)) stop("g must be a downstream directed graph")

  g_dwn <- igraph::adjacent_vertices(g, v = igraph::V(g), mode = "out")
  riv_mouth <- which(sapply(g_dwn, function(x) length(x) == 0))
  return(riv_mouth)
}

Try the SBN package in your browser

Any scripts or data that you put into this service are public.

SBN documentation built on Jan. 18, 2022, 1:08 a.m.