From 79964cccdd9c8303261e8edfd726591e0346fca0 Mon Sep 17 00:00:00 2001 From: edzer Date: Sat, 14 Dec 2024 13:42:55 +0100 Subject: [PATCH] catch polygon full logic error; see #2490 --- R/crs.R | 3 +++ R/sfc.R | 2 +- tests/full.R | 3 +-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/R/crs.R b/R/crs.R index 15053645e..6d2772b6e 100644 --- a/R/crs.R +++ b/R/crs.R @@ -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) } diff --git a/R/sfc.R b/R/sfc.R index 6a422abef..e59bd0a8b 100644 --- a/R/sfc.R +++ b/R/sfc.R @@ -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))) } diff --git a/tests/full.R b/tests/full.R index 8aace5c0f..619683622 100644 --- a/tests/full.R +++ b/tests/full.R @@ -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: