R/subset_edges_as_sf.R

Defines functions subset_edges_as_sf

Documented in subset_edges_as_sf

#' Subset a graph based on optimal route
#'
#' Subsets a graph based on optimal routes that can be used to e.g. calculate
#' summary statistics.
#'
#' @param graph tbl_graph object with the network used to calculate the
#' route
#' @param epath igraph.es object containing the route
#'
#' @return sf object with a subset of the network based on the route
#'
subset_edges_as_sf <- function(graph, epath){
  graph %>%
    subgraph.edges(eids = epath %>% unlist()) %>%
    as_tbl_graph() %>% 
    activate(edges) %>% 
    as_tibble() %>% 
    st_as_sf()
}
kjetilhaukas/shortestpath documentation built on April 28, 2022, 12:06 a.m.