-
Notifications
You must be signed in to change notification settings - Fork 67
Open
Description
#' Filter route network by connected component size
#'
#' Groups a route network using stplanr::rnet_group() and removes
#' components (islands) smaller than a specified size.
#'
#' @param rl An sf object representing a route network (LINESTRING/MULTILINESTRING).
#' @param component_size Integer threshold; components with strictly more than this
#' number of features are retained. Default 10 (matching previous inline logic).
#' @return An sf object filtered to retain only components exceeding the threshold.
#' @examples
#' # rnet_filtered <- rnet_filter(rnet_sf, component_size = 20)
#' @export
rnet_filter <- function(rl, component_size = 10) {
stopifnot(inherits(rl, "sf"))
if (!"geometry" %in% names(rl)) {
stop("Input 'rl' must be an sf object with a geometry column.")
}
rl$group <- stplanr::rnet_group(rl)
rl <- dplyr::group_by(rl, group)
rl <- dplyr::mutate(rl, n = dplyr::n())
rl <- dplyr::filter(rl, n > component_size)
rl <- dplyr::select(rl, -n, -group)
rl <- dplyr::ungroup(rl)
rl
}
Metadata
Metadata
Assignees
Labels
No labels