Skip to content

Commit 683a548

Browse files
committed
use s2 for convex hull; #2250
1 parent c6c02e0 commit 683a548

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# version 1.0-15
22

3+
* `st_convex_hull()` uses `s2::s2_convex_hull()` for geodetic coordinates; #2250
4+
35
* add `directed` argument to `st_line_merge()`; #2264
46

57
* `st_union.sfc()` given `x` and `y` works consistently across geodetic and projected objects; #2262

R/geom-transformers.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ st_boundary.sf = function(x) {
182182
#' nc_g = st_geometry(nc)
183183
#' plot(st_convex_hull(nc_g))
184184
#' plot(nc_g, border = grey(.5), add = TRUE)
185+
#' pt = st_combine(st_sfc(st_point(c(0,80)), st_point(c(120,80)), st_point(c(240,80))))
186+
#' st_convex_hull(pt) # R2
187+
#' st_convex_hull(st_set_crs(pt, 'OGC:CRS84')) # S2
185188
st_convex_hull = function(x)
186189
UseMethod("st_convex_hull")
187190

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

192195
#' @export
193-
st_convex_hull.sfc = function(x)
194-
st_sfc(CPL_geos_op("convex_hull", x, numeric(0), integer(0), numeric(0), logical(0)))
196+
st_convex_hull.sfc = function(x) {
197+
if (isTRUE(st_is_longlat(x)) && sf_use_s2())
198+
st_as_sfc(s2::s2_convex_hull(x), crs = st_crs(x))
199+
else
200+
st_sfc(CPL_geos_op("convex_hull", x, numeric(0), integer(0), numeric(0), logical(0)))
201+
}
195202

196203
#' @export
197204
st_convex_hull.sf = function(x) {

man/geos_unary.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)