Skip to content

Commit

Permalink
closes #2473
Browse files Browse the repository at this point in the history
edzer committed Nov 26, 2024
1 parent c00a188 commit 1e8fca3
Showing 5 changed files with 50 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -270,6 +270,9 @@ S3method(st_m_range,sfc)
S3method(st_make_valid,sf)
S3method(st_make_valid,sfc)
S3method(st_make_valid,sfg)
S3method(st_minimum_bounding_circle,sf)
S3method(st_minimum_bounding_circle,sfc)
S3method(st_minimum_bounding_circle,sfg)
S3method(st_minimum_rotated_rectangle,sf)
S3method(st_minimum_rotated_rectangle,sfc)
S3method(st_minimum_rotated_rectangle,sfg)
@@ -485,6 +488,7 @@ export(st_linestring)
export(st_m_range)
export(st_make_grid)
export(st_make_valid)
export(st_minimum_bounding_circle)
export(st_minimum_rotated_rectangle)
export(st_multilinestring)
export(st_multipoint)
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# version 1.0-20

* `st_minimum_bounding_circle()` returns geometries representing the smallest circle that contains the input; #2473

# version 1.0-19

* fix type checks in C++ GDAL area and length computation functions, anticipating GDAL 3.10.0; #2466, #2468, #2469 by @rsbivand and @rouault
28 changes: 28 additions & 0 deletions R/geom-transformers.R
Original file line number Diff line number Diff line change
@@ -451,6 +451,34 @@ st_minimum_rotated_rectangle.sf = function(x, dTolerance, ...) {
st_set_geometry(x, st_minimum_rotated_rectangle(st_geometry(x)), ...)
}

#' @name geos_unary
#' @details \code{st_minimum_bounding_circle}
#' returns a geometry which represents the "minimum bounding circle",
#' the smallest circle that contains the input.
#' @export
st_minimum_bounding_circle = function(x, ...)
UseMethod("st_minimum_bounding_circle")

#' @export
st_minimum_bounding_circle.sfg = function(x, ...) {
get_first_sfg(st_minimum_bounding_circle(st_sfc(x), ...))
}

#' @export
st_minimum_bounding_circle.sfc = function(x, ...) {
if (compareVersion(CPL_geos_version(), "3.8.0") > -1) { # >=
if (isTRUE(st_is_longlat(x)))
warning("st_minimum_rotated_rectangle does not work correctly for longitude/latitude data")
st_sfc(CPL_geos_op("bounding_circle", x, 0L, integer(0),
dTolerance = 0., logical(0), bOnlyEdges = as.integer(FALSE)))
} else
stop("for st_minimum_bounding_circle, GEOS version 3.8.0 or higher is required")
}

#' @export
st_minimum_bounding_circle.sf = function(x, ...) {
st_set_geometry(x, st_minimum_bounding_circle(st_geometry(x)), ...)
}

#' @name geos_unary
#' @export
7 changes: 7 additions & 0 deletions man/geos_unary.Rd

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

8 changes: 7 additions & 1 deletion src/geos.cpp
Original file line number Diff line number Diff line change
@@ -885,6 +885,13 @@ Rcpp::List CPL_geos_op(std::string op, Rcpp::List sfc,
}
} else
#endif
#ifdef HAVE380
if (op == "bounding_circle") {
double r;
for (size_t i = 0; i < g.size(); i++)
out[i] = geos_ptr(chkNULL(GEOSMinimumBoundingCircle_r(hGEOSCtxt, g[i].get(), &r, NULL)), hGEOSCtxt);
} else
#endif
#ifdef HAVE390
if (op == "inscribed_circle") {
for (size_t i = 0; i < g.size(); i++) {
@@ -906,7 +913,6 @@ Rcpp::List CPL_geos_op(std::string op, Rcpp::List sfc,
return ret;
}


// [[Rcpp::export]]
Rcpp::List CPL_geos_voronoi(Rcpp::List sfc, Rcpp::List env, double dTolerance = 0.0, int bOnlyEdges = 1) {

0 comments on commit 1e8fca3

Please sign in to comment.