From 9e97b5b62f1a7fb585c973ecee295868ce28a5ad Mon Sep 17 00:00:00 2001 From: Eli Pousson Date: Fri, 28 Apr 2023 22:32:53 -0400 Subject: [PATCH] feat: replace st_concave_hull with `st_concave_hull_ext()` --- DESCRIPTION | 1 - NEWS.md | 4 +++ R/st_concave_hull.R | 29 ++++++++--------- _pkgdown.yml | 2 +- man/st_concave_hull.Rd | 32 ------------------- man/st_concave_hull_ext.Rd | 29 +++++++++++++++++ ...cave_hull.R => test-st_concave_hull_ext.R} | 8 ++--- 7 files changed, 51 insertions(+), 54 deletions(-) delete mode 100644 man/st_concave_hull.Rd create mode 100644 man/st_concave_hull_ext.Rd rename tests/testthat/{test-st_concave_hull.R => test-st_concave_hull_ext.R} (58%) diff --git a/DESCRIPTION b/DESCRIPTION index 33a02c1..9a4f3c9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,7 +30,6 @@ Imports: units, vctrs Suggests: - concaveman, covr, esri2sf (>= 0.1.1), exiftoolr, diff --git a/NEWS.md b/NEWS.md index d09e9c0..ed3127d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ +# sfext development + +* Replace st_concave_hull with `st_concave_hull_ext()` + # sfext 0.1.1 (2023-03-28) * Add `is_wgs84()` + `as_wgs84()` functions. diff --git a/R/st_concave_hull.R b/R/st_concave_hull.R index c3ed94f..726e90c 100644 --- a/R/st_concave_hull.R +++ b/R/st_concave_hull.R @@ -4,21 +4,18 @@ #' @param by Column name to use for grouping and combining geometry, Default: #' `NULL` #' @param centroid If `TRUE`, use centroids for geometry of x, Default: `FALSE` -#' @inheritParams concaveman::concaveman -#' @seealso -#' \code{\link[concaveman]{concaveman}} -#' @rdname st_concave_hull +#' @inheritParams sf::st_concave_hull +#' @rdname st_concave_hull_ext #' @export -#' @importFrom sf st_centroid st_combine st_cast st_make_valid st_set_geometry +#' @importFrom sf st_centroid st_combine st_cast st_make_valid st_concave_hull +#' st_set_geometry #' @importFrom dplyr summarise #' @importFrom purrr map_dfr -st_concave_hull <- function(x, - by = NULL, - centroid = FALSE, - concavity = 2, - length_threshold = 0) { - rlang::check_installed("concaveman") - +st_concave_hull_ext <- function(x, + by = NULL, + centroid = FALSE, + ratio = 0.5, + allow_holes = FALSE) { check_sf(x, ext = "sfc") return_sfc <- FALSE @@ -55,10 +52,10 @@ st_concave_hull <- function(x, purrr::map_dfr( as_sfc(x), ~ sf::st_make_valid( - concaveman::concaveman( - points = as_sf(.x), - concavity = concavity, - length_threshold = length_threshold + sf::st_concave_hull( + x = as_sf(.x), + ratio = ratio, + allow_holes = allow_holes ) ) ) diff --git a/_pkgdown.yml b/_pkgdown.yml index 2e7fc32..1a307cb 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -30,7 +30,7 @@ reference: - '`st_buffer_ext`' - '`st_erase`' - '`st_clip`' - - '`st_concave_hull`' + - '`st_concave_hull_ext`' - '`st_union_ext`' - '`st_join_ext`' - '`st_filter_ext`' diff --git a/man/st_concave_hull.Rd b/man/st_concave_hull.Rd deleted file mode 100644 index 78e121f..0000000 --- a/man/st_concave_hull.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/st_concave_hull.R -\name{st_concave_hull} -\alias{st_concave_hull} -\title{Make a concave hull around simple feature object by attribute} -\usage{ -st_concave_hull( - x, - by = NULL, - centroid = FALSE, - concavity = 2, - length_threshold = 0 -) -} -\arguments{ -\item{x}{A sf object.} - -\item{by}{Column name to use for grouping and combining geometry, Default: -\code{NULL}} - -\item{centroid}{If \code{TRUE}, use centroids for geometry of x, Default: \code{FALSE}} - -\item{concavity}{a relative measure of concavity. 1 results in a relatively detailed shape, Infinity results in a convex hull. You can use values lower than 1, but they can produce pretty crazy shapes.} - -\item{length_threshold}{when a segment length is under this threshold, it stops being considered for further detalization. Higher values result in simpler shapes.} -} -\description{ -Make a concave hull around simple feature object by attribute -} -\seealso{ -\code{\link[concaveman]{concaveman}} -} diff --git a/man/st_concave_hull_ext.Rd b/man/st_concave_hull_ext.Rd new file mode 100644 index 0000000..d36bc20 --- /dev/null +++ b/man/st_concave_hull_ext.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/st_concave_hull.R +\name{st_concave_hull_ext} +\alias{st_concave_hull_ext} +\title{Make a concave hull around simple feature object by attribute} +\usage{ +st_concave_hull_ext( + x, + by = NULL, + centroid = FALSE, + ratio = 0.5, + allow_holes = FALSE +) +} +\arguments{ +\item{x}{A sf object.} + +\item{by}{Column name to use for grouping and combining geometry, Default: +\code{NULL}} + +\item{centroid}{If \code{TRUE}, use centroids for geometry of x, Default: \code{FALSE}} + +\item{ratio}{numeric; fraction convex: 1 returns the convex hulls, 0 maximally concave hulls} + +\item{allow_holes}{logical; if \code{TRUE}, the resulting concave hull may have holes} +} +\description{ +Make a concave hull around simple feature object by attribute +} diff --git a/tests/testthat/test-st_concave_hull.R b/tests/testthat/test-st_concave_hull_ext.R similarity index 58% rename from tests/testthat/test-st_concave_hull.R rename to tests/testthat/test-st_concave_hull_ext.R index 605a7b1..d8fc467 100644 --- a/tests/testthat/test-st_concave_hull.R +++ b/tests/testthat/test-st_concave_hull_ext.R @@ -1,17 +1,17 @@ -test_that("st_concave_hull works", { +test_that("st_concave_hull_ext works", { nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc$group <- sample(c("A", "B", "C"), size = nrow(nc), replace = TRUE) expect_s3_class( - st_concave_hull(nc), + st_concave_hull_ext(nc), "sf" ) expect_s3_class( - st_concave_hull(sf::st_geometry(nc)), + st_concave_hull_ext(sf::st_geometry(nc)), "sfc" ) expect_identical( - nrow(st_concave_hull(nc, by = "group")), + nrow(st_concave_hull_ext(nc, by = "group")), 3L ) })