Skip to content

Commit

Permalink
use s2 for convex hull; #2250
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Dec 10, 2023
1 parent c6c02e0 commit 683a548
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# version 1.0-15

* `st_convex_hull()` uses `s2::s2_convex_hull()` for geodetic coordinates; #2250

* add `directed` argument to `st_line_merge()`; #2264

* `st_union.sfc()` given `x` and `y` works consistently across geodetic and projected objects; #2262
Expand Down
11 changes: 9 additions & 2 deletions R/geom-transformers.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ st_boundary.sf = function(x) {
#' nc_g = st_geometry(nc)
#' plot(st_convex_hull(nc_g))
#' plot(nc_g, border = grey(.5), add = TRUE)
#' pt = st_combine(st_sfc(st_point(c(0,80)), st_point(c(120,80)), st_point(c(240,80))))
#' st_convex_hull(pt) # R2
#' st_convex_hull(st_set_crs(pt, 'OGC:CRS84')) # S2
st_convex_hull = function(x)
UseMethod("st_convex_hull")

Expand All @@ -190,8 +193,12 @@ st_convex_hull.sfg = function(x)
get_first_sfg(st_convex_hull(st_sfc(x)))

#' @export
st_convex_hull.sfc = function(x)
st_sfc(CPL_geos_op("convex_hull", x, numeric(0), integer(0), numeric(0), logical(0)))
st_convex_hull.sfc = function(x) {
if (isTRUE(st_is_longlat(x)) && sf_use_s2())
st_as_sfc(s2::s2_convex_hull(x), crs = st_crs(x))
else
st_sfc(CPL_geos_op("convex_hull", x, numeric(0), integer(0), numeric(0), logical(0)))
}

#' @export
st_convex_hull.sf = function(x) {
Expand Down
3 changes: 3 additions & 0 deletions man/geos_unary.Rd

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

0 comments on commit 683a548

Please sign in to comment.