Skip to content

Commit

Permalink
catch polygon full logic error; see #2490
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Dec 14, 2024
1 parent 50f705f commit 79964cc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 3 additions & 0 deletions R/crs.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ make_crs = function(x) {
if (!is.na(start_crs) && !is.na(end_crs) && start_crs != end_crs)
warning("st_crs<- : replacing crs does not reproject data; use st_transform for that", call. = FALSE)

if (is.na(end_crs) && !is.na(start_crs) && isTRUE(st_is_longlat(start_crs)) && any(st_is_full(x)))
stop("To set the crs to NA, first remove the full polygons; see: st_is_full()")

structure(x, crs = end_crs)
}

Expand Down
2 changes: 1 addition & 1 deletion R/sfc.R
Original file line number Diff line number Diff line change
Expand Up @@ -656,5 +656,5 @@ st_is_full.sf = function(x, ...) {
#' @export
#' @name st_is_full
st_is_full.bbox = function(x, ...) {
sf_use_s2() && st_is_longlat(x) && all(x == c(-180,-90,180,90))
isTRUE(sf_use_s2() && st_is_longlat(x) && all(x == c(-180,-90,180,90)))
}
3 changes: 1 addition & 2 deletions tests/full.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ st_bbox(f[2])
st_is_valid(f) # full polygon NA: right, we don't know the CRS
st_crs(f) = 'OGC:CRS84' # geodetic:
st_is_valid(f)
st_crs(f) = NA
try(st_make_valid(f))
try(st_set_crs(f, NA)) # errors
st_crs(f) = 'OGC:CRS84' # geodetic:
st_make_valid(f)
# mixed geometries:
Expand Down

0 comments on commit 79964cc

Please sign in to comment.