diff --git a/NAMESPACE b/NAMESPACE index 8a41691..23096b1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -74,6 +74,7 @@ importFrom(rlang,`%||%`) importFrom(rlang,sym) importFrom(sf,`st_crs<-`) importFrom(sf,`st_geometry<-`) +importFrom(sf,sf_use_s2) importFrom(sf,st_agr) importFrom(sf,st_as_sf) importFrom(sf,st_as_sfc) diff --git a/R/summarise_geometry.R b/R/summarise_geometry.R index 725ce61..28fc96c 100644 --- a/R/summarise_geometry.R +++ b/R/summarise_geometry.R @@ -61,7 +61,7 @@ summarize_geometry_union = summarise_geometry_union #' @describeIn summarise_geometry computes the geometry summary as the centroid #' of the union and dissolve of the changing geometries #' @inheritParams summarise_geometry_union -#' @importFrom sf st_centroid +#' @importFrom sf st_centroid sf_use_s2 #' @export summarise_geometry_centroid = function(x, group_id = NULL, @@ -70,7 +70,7 @@ summarise_geometry_centroid = function(x, x_unioned = st_summarise_polys(x, group_id = group_id, sf_column_name = sf_column_name, - do_union = TRUE, + do_union = sf::sf_use_s2(), .checks = .checks) x_centroid = sf::st_centroid(x_unioned) x_centroid @@ -108,6 +108,7 @@ summarise_geometry_bbox = function(x, } #' @rdname summarise_geometry +#' @importFrom sf st_convex_hull sf_use_s2 #' @export summarize_geometry_bbox = summarise_geometry_bbox @@ -123,7 +124,7 @@ summarise_geometry_convex_hull = function(x, x_unioned = st_summarise_polys(x, group_id = group_id, sf_column_name = sf_column_name, - do_union = TRUE, + do_union = sf::sf_use_s2(), .checks = .checks) x_conv_hull = sf::st_convex_hull(x_unioned) x_conv_hull diff --git a/R/utils.R b/R/utils.R index a7f4294..156ce85 100644 --- a/R/utils.R +++ b/R/utils.R @@ -47,7 +47,8 @@ st_bbox_by_feature = function(x) { #' @noRd #' @importFrom sf st_make_valid st_cast st_union st_summarise_polys = function(x, group_id, sf_column_name, - do_union = TRUE, .checks = TRUE) { + do_union = sf::sf_use_s2(), + .checks = TRUE) { if(.checks){ # group_id: Defaults to the first column of x, if not sfc or temporal class @@ -66,6 +67,10 @@ st_summarise_polys = function(x, group_id, sf_column_name, } x_groupped = split(x[[sf_column_name]], x[[group_id]]) + # Combining all the polygon features into one single polygon is a much + # cheaper operation than doing a union operation. + # However the validity of the multipolygon will throw errors with s2 geometry + # so the default is to union when s2 is active in sf if(do_union) { do.call( "c",