R/segmentize.R

Defines functions sf_segmentize_ll sf_segmentize

Documented in sf_segmentize sf_segmentize_ll

#' Segmentize your simple features
#'
#' No weird tricks, just extra vertices based on a distance. These functions work consistently, if you
#' want ellipsoidal methods you get them. You want planar?  Here you go!
#'
#' Use 'sf_segmentize' to segmentize your data as-is. Use 'sf_segmentize_ll' to segmentize using
#' ellipsoidal tricks. Data is unprojected for this purpose if need be.
#'
#' @aliases sf_segmentize_ll
#' @param x sf object
#' @param dx distance in units of the data
#' @param dfMaxLength distance in metres (for use in ellipsoidal approximate segmentize)
#' @param ... passed to st_segmentize, but unused currently
#' @param ll_proj projection string used for longitude latitude (for ellipsoidal pathway)
#'
#' @return
#' @export
#'
#' @examples
sf_segmentize <- function(x, dx, ...) {
  print("BASF")
  ## turn off the CRS (so we use normal numbers)
  crs <- sf::st_crs(x)
  x <- sf::st_set_crs(x, NA)
  x <- sf::st_segmentize(x, dx, ...)
  sf::st_set_crs(x, crs)
}

#' @name sf_segmentize
#' @export
sf_segmentize_ll <- function(x, dfMaxLength, ..., ll_proj = "OGC:CRS84") {
  inputll <- sf::st_is_longlat(x)
  if (!inputll) {
    crs <- sf::st_crs(x)
    xx <- sf::st_transform(x, ll_proj)
  }
  xx <- sf::st_segmentize(x, dfMaxLength = dfMaxLength, ...)
  if (!inputll) {
    xx <- sf::st_transform(x, crs)
  }
  xx
}
mdsumner/basf documentation built on Sept. 11, 2022, 1:08 p.m.