Skip to content

Commit

Permalink
feat: replace st_concave_hull with st_concave_hull_ext()
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson committed Apr 29, 2023
1 parent e25ca71 commit 9e97b5b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 54 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Imports:
units,
vctrs
Suggests:
concaveman,
covr,
esri2sf (>= 0.1.1),
exiftoolr,
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<!-- NEWS.md is maintained by https://cynkra.github.io/fledge, do not edit -->

# sfext development

* Replace st_concave_hull with `st_concave_hull_ext()`

# sfext 0.1.1 (2023-03-28)

* Add `is_wgs84()` + `as_wgs84()` functions.
Expand Down
29 changes: 13 additions & 16 deletions R/st_concave_hull.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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`'
Expand Down
32 changes: 0 additions & 32 deletions man/st_concave_hull.Rd

This file was deleted.

29 changes: 29 additions & 0 deletions man/st_concave_hull_ext.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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
)
})

0 comments on commit 9e97b5b

Please sign in to comment.