R/fun-sfc_as_cols.R

Defines functions sfc_as_cols

## add from and to coordinates for each pipe
#' @export
sfc_as_cols <- function(x, names = c("x","y")) {
  stopifnot(inherits(x,"sf") && inherits(sf::st_geometry(x),"sfc_POINT"))
  ret <- do.call(rbind,sf::st_geometry(x))
  ret <- tibble::as_tibble(ret)
  stopifnot(length(names) == ncol(ret))
  ret <- setNames(ret,names)
  dplyr::bind_cols(x,ret)
}
capellett/scsf documentation built on Sept. 6, 2024, 7:46 a.m.