Skip to content

Commit

Permalink
provide more helpful warning messages; #2315
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Jan 17, 2024
1 parent 7472a21 commit 5b096aa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R/valid.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ st_make_valid.sfc = function(x, ..., oriented = FALSE, s2_options = s2::s2_optio
geos_method = "valid_structure", geos_keep_collapsed = TRUE) {
crs = st_crs(x)
if (sf_use_s2() && isTRUE(st_is_longlat(x))) {
stopifnot(missing(geos_method), missing(geos_keep_collapsed))
if (!missing(geos_method) || !missing(geos_keep_collapsed))
warning("arguments geos_method and geos_keep_collapsed are ignored for geodetic coordinates as sf_use_s2() is TRUE")
s2 = s2::as_s2_geography(st_as_binary(st_set_precision(x, 0.0)), oriented = oriented, check = FALSE)
if (st_precision(x) != 0 && missing(s2_options))
s2_options = s2::s2_options(snap = s2::s2_snap_precision(st_precision(x)), ...)
s2 = s2::s2_rebuild(s2, s2_options)
st_as_sfc(s2, crs = crs)
} else if (compareVersion(CPL_geos_version(), "3.8.0") == -1) {
stopifnot(missing(geos_method), missing(geos_keep_collapsed))
if (!missing(geos_method) || !missing(geos_keep_collapsed))
warning("ignoring arguments geos_method and geos_keep_collapsed, as these require GEOS >= 3.8.0")
if (!requireNamespace("lwgeom", quietly = TRUE))
stop("package lwgeom required, please install it first") # nocov
st_sfc(lwgeom::lwgeom_make_valid(x), crs = crs)
Expand Down

0 comments on commit 5b096aa

Please sign in to comment.