From 12bc8a16b04aec2997c3194021f311b7360f06fe Mon Sep 17 00:00:00 2001 From: edzer Date: Thu, 10 Sep 2026 21:53:37 +0200 Subject: [PATCH 01/27] update --- R/aggregate.R | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/R/aggregate.R b/R/aggregate.R index d288ef09d..de288408b 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -216,17 +216,29 @@ st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = st_interpolate_aw.stars = function(x, to, extensive, ...) { if (! requireNamespace("stars", quietly = TRUE)) stop("package stars required, please install it first") - ret = st_interpolate_aw(st_as_sf(x), to, extensive, ...) - geom = attr(ret, "sf_column") - dx = dim(x) - if (length(dx) > 2 && length(x) == 1 && length(ret) > 2) { - ret = merge(stars::st_as_stars(ret)) - nd = names(stars::st_dimensions(x)) - ret = stars::st_set_dimensions(ret, seq_along(dx), - names = c(geom, paste0(nd[-(1:2)], collapse = "."))) - setNames(ret, names(x)) - } else - ret + + if (st_raster_type(x) == "regular" && + compareVersion(gsub("[a-zA-Z].+$", "", sf_extSoftVersion()[["GEOS"]]), "3.14.0") > -1) { + # we HAVE_GEOS_3_14_0 + if (!inherits(to, "sf") && !inherits(to, "sfc")) { + to <- try(st_as_sf(to)) + if (inherits(to, "try-error")) + stop("st_interpolate_aw requires geometries in argument to") + } + stop("not yet implemented") + } else { + ret = st_interpolate_aw(st_as_sf(x), to, extensive, ...) + geom = attr(ret, "sf_column") + dx = dim(x) + if (length(dx) > 2 && length(x) == 1 && length(ret) > 2) { + ret = merge(stars::st_as_stars(ret)) + nd = names(stars::st_dimensions(x)) + ret = stars::st_set_dimensions(ret, seq_along(dx), + names = c(geom, paste0(nd[-(1:2)], collapse = "."))) + setNames(ret, names(x)) + } else + ret + } } dasymetric = function(x, to, extensive, keep_NA, include_non_intersected) { From 7105094b0e3da06712f0a9076a6f402153bde1b7 Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 11 Sep 2026 09:11:06 +0200 Subject: [PATCH 02/27] use GEOSGridIntersectionFractions_r in st_interpolate_aw() --- R/RcppExports.R | 4 ++++ R/aggregate.R | 6 +++++- src/RcppExports.cpp | 12 ++++++++++++ src/geos.cpp | 28 ++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/R/RcppExports.R b/R/RcppExports.R index f53a1becc..dc18f58ee 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -281,6 +281,10 @@ CPL_line_interpolate <- function(lines, dists, normalized) { .Call(`_sf_CPL_line_interpolate`, lines, dists, normalized) } +CPL_grid_intersection_fractions <- function(p, geoms) { + .Call(`_sf_CPL_grid_intersection_fractions`, p, geoms) +} + CPL_hex_to_raw <- function(cx) { .Call(`_sf_CPL_hex_to_raw`, cx) } diff --git a/R/aggregate.R b/R/aggregate.R index de288408b..6013d0a0f 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -225,7 +225,11 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { if (inherits(to, "try-error")) stop("st_interpolate_aw requires geometries in argument to") } - stop("not yet implemented") + # stop("not yet implemented") + if (!identical(match(attr(st_dimensions(x), "raster")$dimensions, names(dim(x))), 1:2)) + stop("raster dimensions need to be as position 1 and 2; use aperm to rearrange") + w = CPL_grid_intersection_fractions(c(st_bbox(x), dim(x)), to) + w } else { ret = st_interpolate_aw(st_as_sf(x), to, extensive, ...) geom = attr(ret, "sf_column") diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 3cab54a71..b16d2b50d 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -897,6 +897,17 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// CPL_grid_intersection_fractions +Rcpp::NumericVector CPL_grid_intersection_fractions(Rcpp::NumericVector p, Rcpp::List geoms); +RcppExport SEXP _sf_CPL_grid_intersection_fractions(SEXP pSEXP, SEXP geomsSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::traits::input_parameter< Rcpp::NumericVector >::type p(pSEXP); + Rcpp::traits::input_parameter< Rcpp::List >::type geoms(geomsSEXP); + rcpp_result_gen = Rcpp::wrap(CPL_grid_intersection_fractions(p, geoms)); + return rcpp_result_gen; +END_RCPP +} // CPL_hex_to_raw Rcpp::List CPL_hex_to_raw(Rcpp::CharacterVector cx); RcppExport SEXP _sf_CPL_hex_to_raw(SEXP cxSEXP) { @@ -1497,6 +1508,7 @@ static const R_CallMethodDef CallEntries[] = { {"_sf_CPL_nary_intersection", (DL_FUNC) &_sf_CPL_nary_intersection, 1}, {"_sf_CPL_line_project", (DL_FUNC) &_sf_CPL_line_project, 3}, {"_sf_CPL_line_interpolate", (DL_FUNC) &_sf_CPL_line_interpolate, 3}, + {"_sf_CPL_grid_intersection_fractions", (DL_FUNC) &_sf_CPL_grid_intersection_fractions, 2}, {"_sf_CPL_hex_to_raw", (DL_FUNC) &_sf_CPL_hex_to_raw, 1}, {"_sf_CPL_raw_to_hex", (DL_FUNC) &_sf_CPL_raw_to_hex, 1}, {"_sf_CPL_read_mdim", (DL_FUNC) &_sf_CPL_read_mdim, 8}, diff --git a/src/geos.cpp b/src/geos.cpp index 5d6f391f8..d2944450d 100644 --- a/src/geos.cpp +++ b/src/geos.cpp @@ -38,6 +38,9 @@ # if GEOS_VERSION_MINOR >= 12 # define HAVE312 # endif +# if GEOS_VERSION_MINOR >= 14 +# define HAVE314 +# endif #else # if GEOS_VERSION_MAJOR > 3 # define HAVE340 @@ -49,6 +52,8 @@ # define HAVE310 # define HAVE3101 # define HAVE311 +# define HAVE312 +# define HAVE314 # endif #endif @@ -1609,3 +1614,26 @@ Rcpp::List CPL_line_interpolate(Rcpp::List lines, Rcpp::NumericVector dists, boo Rcpp::List ret(sfc_from_geometry(hGEOSCtxt, p, dim)); return ret; } + +// [[Rcpp::export(rng=false)]] +Rcpp::NumericVector CPL_grid_intersection_fractions(Rcpp::NumericVector p, Rcpp::List geoms) { + GEOSContextScope hGEOSCtxt; + int dim = 2; + unsigned ncell = p[4] * p[5]; + std::vector g = geometries_from_sfc(hGEOSCtxt, geoms, &dim); + std::vector buf(ncell); // nx * ny * n.geoms + Rcpp::NumericVector ret(ncell * g.size()); + for (int i = 0; i < (int) g.size(); i++) { +#ifdef HAVE314 + if (GEOSGridIntersectionFractions_r(hGEOSCtxt, g[i].get(), p[0], p[1], p[2], p[3], (unsigned) p[4], (unsigned) p[5], buf.data())) +#else + Rcpp::stop("GEOS >= 3.14.0 required"); +#endif + for (int j = 0; j < ncell; j++) + ret[i * ncell + j] = buf[j]; + } + Rcpp::IntegerVector d(2); + d[0] = ncell; d[1] = g.size(); + ret.attr("dim") = d; + return ret; +} From f0f431db0820913a01014aa2548000cc2a6b3f3a Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 11 Sep 2026 16:25:59 +0200 Subject: [PATCH 03/27] fix --- R/aggregate.R | 24 +++++++++++++++++++++--- src/geos.cpp | 4 +++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/R/aggregate.R b/R/aggregate.R index 6013d0a0f..245f328b0 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -225,11 +225,29 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { if (inherits(to, "try-error")) stop("st_interpolate_aw requires geometries in argument to") } - # stop("not yet implemented") + # check x and y are first two dimensions: if (!identical(match(attr(st_dimensions(x), "raster")$dimensions, names(dim(x))), 1:2)) stop("raster dimensions need to be as position 1 and 2; use aperm to rearrange") - w = CPL_grid_intersection_fractions(c(st_bbox(x), dim(x)), to) - w + if (st_dimensions(x)[[2]]$delta > 0) + stop("only implemented for negative N-S cellsize") + w = CPL_grid_intersection_fractions(c(st_bbox(x), dim(x)), st_geometry(to)) + weight = function(a, w, extensive) { + d = dim(a) + dim(a) = c(prod(d[1:2]), prod(d[-(1:2)])) + ret = t(w) %*% a + if (!extensive) { + cs = colSums(w) + cs[cs == 0] = 1 + ret = ret / cs + } + dim(ret) = c(ncol(w), d[-(1:2)]) + ret + } + ret = lapply(x, weight, w, extensive) + dm = st_dimensions(x) + dm[[1]] = NULL + dm[[2]] = create_dimension(values = st_geometry(to)) + st_as_stars(ret, dimensions = dm) } else { ret = st_interpolate_aw(st_as_sf(x), to, extensive, ...) geom = attr(ret, "sf_column") diff --git a/src/geos.cpp b/src/geos.cpp index d2944450d..776f7e449 100644 --- a/src/geos.cpp +++ b/src/geos.cpp @@ -1624,13 +1624,15 @@ Rcpp::NumericVector CPL_grid_intersection_fractions(Rcpp::NumericVector p, Rcpp: std::vector buf(ncell); // nx * ny * n.geoms Rcpp::NumericVector ret(ncell * g.size()); for (int i = 0; i < (int) g.size(); i++) { + for (int j = 0; j < ncell; j++) + buf[j] = 0.0; // initialize, needed for i > 0! #ifdef HAVE314 if (GEOSGridIntersectionFractions_r(hGEOSCtxt, g[i].get(), p[0], p[1], p[2], p[3], (unsigned) p[4], (unsigned) p[5], buf.data())) #else Rcpp::stop("GEOS >= 3.14.0 required"); #endif for (int j = 0; j < ncell; j++) - ret[i * ncell + j] = buf[j]; + ret[i * ncell + j] = (double) buf[j]; } Rcpp::IntegerVector d(2); d[0] = ncell; d[1] = g.size(); From 55745e6fdf9662d7ba2dce4781ce710b66e0c8f3 Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 11 Sep 2026 16:34:38 +0200 Subject: [PATCH 04/27] omit create_dimension() --- R/aggregate.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/aggregate.R b/R/aggregate.R index 245f328b0..e34bb8db3 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -246,7 +246,9 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { ret = lapply(x, weight, w, extensive) dm = st_dimensions(x) dm[[1]] = NULL - dm[[2]] = create_dimension(values = st_geometry(to)) + g = st_geometry(to) + dm[[2]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, + refsys = st_crs(g), point = any(st_dimension(g) > 0), values = g), class = "dimension") st_as_stars(ret, dimensions = dm) } else { ret = st_interpolate_aw(st_as_sf(x), to, extensive, ...) From 63abe329d4f04ab02ddb5cdb9ffbdc2521e7456d Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 11 Sep 2026 16:44:36 +0200 Subject: [PATCH 05/27] fix dimensions --- R/aggregate.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/aggregate.R b/R/aggregate.R index e34bb8db3..b501670c1 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -246,9 +246,11 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { ret = lapply(x, weight, w, extensive) dm = st_dimensions(x) dm[[1]] = NULL + attr(dm, "raster") = NULL g = st_geometry(to) - dm[[2]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, + dm[[1]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, refsys = st_crs(g), point = any(st_dimension(g) > 0), values = g), class = "dimension") + names(dm)[1] = "geometry" st_as_stars(ret, dimensions = dm) } else { ret = st_interpolate_aw(st_as_sf(x), to, extensive, ...) From 4a42b5b777f440176ada8108898ae399c6411001 Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 11 Sep 2026 16:54:31 +0200 Subject: [PATCH 06/27] fix raster --- R/aggregate.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/aggregate.R b/R/aggregate.R index b501670c1..5601b1aee 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -246,7 +246,7 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { ret = lapply(x, weight, w, extensive) dm = st_dimensions(x) dm[[1]] = NULL - attr(dm, "raster") = NULL + attr(dm, "raster")$dimensions = c(NA_character_, NA_character_) g = st_geometry(to) dm[[1]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, refsys = st_crs(g), point = any(st_dimension(g) > 0), values = g), class = "dimension") From 6305d3dd52a1aa3aecc929de772240c0c99b158e Mon Sep 17 00:00:00 2001 From: edzer Date: Mon, 14 Sep 2026 12:27:44 +0200 Subject: [PATCH 07/27] add interpolate_aw(sf, stars) --- R/aggregate.R | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/R/aggregate.R b/R/aggregate.R index 5601b1aee..2e62a742a 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -152,6 +152,19 @@ st_interpolate_aw = function(x, to, extensive, ...) UseMethod("st_interpolate_aw st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = FALSE, include_non_intersected = FALSE, weights = character(0)) { + if (! all_constant(x)) + warning("st_interpolate_aw assumes attributes are constant or uniform over areas of x") + + if (inherits(to, "stars") && length(weights) == 0) { + if (! requireNamespace("stars", quietly = TRUE)) + stop("package stars required, please install it first") + if (st_raster_type(x) == "regular" && + compareVersion(gsub("[a-zA-Z].+$", "", sf_extSoftVersion()[["GEOS"]]), "3.14.0") > -1) { + return(interpolate_aw_sf_stars(x, to, extensive, ..., keep_NA = keep_NA, na.rm = na.rm, + include_non_intersected = include_non_intersected)) + } + } + if (!inherits(to, "sf") && !inherits(to, "sfc")) { to <- try(st_as_sf(to)) if (inherits(to, "try-error")) @@ -165,8 +178,6 @@ st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = return(dasymetric(x, to[weights], extensive, keep_NA, include_non_intersected)) } - if (! all_constant(x)) - warning("st_interpolate_aw assumes attributes are constant or uniform over areas of x") i = st_intersection(st_geometry(x), st_geometry(to), dimensions = "polygon") idx = attr(i, "idx") @@ -220,14 +231,14 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { if (st_raster_type(x) == "regular" && compareVersion(gsub("[a-zA-Z].+$", "", sf_extSoftVersion()[["GEOS"]]), "3.14.0") > -1) { # we HAVE_GEOS_3_14_0 - if (!inherits(to, "sf") && !inherits(to, "sfc")) { + if (!inherits(to, "sf") && !inherits(to, "sfc")) { # the stars-stars is for another day to <- try(st_as_sf(to)) if (inherits(to, "try-error")) stop("st_interpolate_aw requires geometries in argument to") } # check x and y are first two dimensions: if (!identical(match(attr(st_dimensions(x), "raster")$dimensions, names(dim(x))), 1:2)) - stop("raster dimensions need to be as position 1 and 2; use aperm to rearrange") + stop("raster dimensions need to be at position 1 and 2; use aperm to rearrange") if (st_dimensions(x)[[2]]$delta > 0) stop("only implemented for negative N-S cellsize") w = CPL_grid_intersection_fractions(c(st_bbox(x), dim(x)), st_geometry(to)) @@ -249,10 +260,10 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { attr(dm, "raster")$dimensions = c(NA_character_, NA_character_) g = st_geometry(to) dm[[1]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, - refsys = st_crs(g), point = any(st_dimension(g) > 0), values = g), class = "dimension") + refsys = st_crs(g), point = any(st_dimension(g) > 0), values = g), class = "dimension") names(dm)[1] = "geometry" st_as_stars(ret, dimensions = dm) - } else { + } else { # convert stars to sf... ret = st_interpolate_aw(st_as_sf(x), to, extensive, ...) geom = attr(ret, "sf_column") dx = dim(x) @@ -267,6 +278,28 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { } } +interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na.rm = na.rm, + include_non_intersected = include_non_intersected) { + + # st_interpolate_aw(x, st_as_sf(to), extensive, ...) + + stopifnot(inherits(to, "stars"), inherits(x, "sf")) + # check x and y are first two dimensions: + if (!identical(match(attr(st_dimensions(to), "raster")$dimensions, names(dim(to))), 1:2)) + stop("raster dimensions of to need to be at position 1 and 2; use aperm to rearrange") + if (st_dimensions(to)[[2]]$delta > 0) + stop("only implemented for negative N-S cellsize") + w = CPL_grid_intersection_fractions(c(st_bbox(to), dim(to)), st_geometry(x)) + areas = st_area(x) + x = as.matrix(st_set_geometry(x, NULL)) + ret = w %*% x + dim(ret) = c(dim(to)[1:2], ncol(x)) + dm = st_dimensions(x)[1:2] + dm[["attribute"]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, + point = any(st_dimension(g) > 0), values = dimnames(x)[[2]]), class = "dimension") + st_as_stars(list(ret), dimensions = st_dimensions(to)) +} + dasymetric = function(x, to, extensive, keep_NA, include_non_intersected) { stopifnot(isTRUE(extensive), !keep_NA, !include_non_intersected) # later... stopifnot(length(to) == 2) From ba59b6749016899a4d91933b7497783fdeeaa490 Mon Sep 17 00:00:00 2001 From: edzer Date: Mon, 14 Sep 2026 12:32:34 +0200 Subject: [PATCH 08/27] add interpolate_aw for sf, stars --- R/aggregate.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/aggregate.R b/R/aggregate.R index 2e62a742a..3d91d3b35 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -290,9 +290,14 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. if (st_dimensions(to)[[2]]$delta > 0) stop("only implemented for negative N-S cellsize") w = CPL_grid_intersection_fractions(c(st_bbox(to), dim(to)), st_geometry(x)) - areas = st_area(x) + g = st_geometry(x) x = as.matrix(st_set_geometry(x, NULL)) - ret = w %*% x + ret = if (extensive) { + areas = rep(st_area(g), each = ncol(w)) + cellsize = st_area(to) + w %*% x * units::drop_units(cellsize / areas) + } else + w %*% x dim(ret) = c(dim(to)[1:2], ncol(x)) dm = st_dimensions(x)[1:2] dm[["attribute"]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, From dcc4eea5b3e0e0c2564f2bdc9693072e69755f14 Mon Sep 17 00:00:00 2001 From: edzer Date: Mon, 14 Sep 2026 13:35:15 +0200 Subject: [PATCH 09/27] typo --- R/aggregate.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/aggregate.R b/R/aggregate.R index 3d91d3b35..c47c8d409 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -158,7 +158,7 @@ st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = if (inherits(to, "stars") && length(weights) == 0) { if (! requireNamespace("stars", quietly = TRUE)) stop("package stars required, please install it first") - if (st_raster_type(x) == "regular" && + if (st_raster_type(to) == "regular" && compareVersion(gsub("[a-zA-Z].+$", "", sf_extSoftVersion()[["GEOS"]]), "3.14.0") > -1) { return(interpolate_aw_sf_stars(x, to, extensive, ..., keep_NA = keep_NA, na.rm = na.rm, include_non_intersected = include_non_intersected)) From fb0a866c312585eaed517f917905c29ab1d043a9 Mon Sep 17 00:00:00 2001 From: edzer Date: Mon, 14 Sep 2026 14:42:50 +0200 Subject: [PATCH 10/27] set NAs, scale --- R/aggregate.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/aggregate.R b/R/aggregate.R index c47c8d409..c1ba72f7e 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -292,12 +292,16 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. w = CPL_grid_intersection_fractions(c(st_bbox(to), dim(to)), st_geometry(x)) g = st_geometry(x) x = as.matrix(st_set_geometry(x, NULL)) + ret = w %*% x + rs = rowSums(w) ret = if (extensive) { areas = rep(st_area(g), each = ncol(w)) cellsize = st_area(to) - w %*% x * units::drop_units(cellsize / areas) - } else - w %*% x + ret * units::drop_units(cellsize / areas) + } else { + ret[rs == 0.0] = NA + ret / rs + } dim(ret) = c(dim(to)[1:2], ncol(x)) dm = st_dimensions(x)[1:2] dm[["attribute"]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, From 7b95ee067b7cdf5b32e723cd2d26c496d136bfb4 Mon Sep 17 00:00:00 2001 From: edzer Date: Mon, 14 Sep 2026 22:30:16 +0200 Subject: [PATCH 11/27] name --- R/aggregate.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/aggregate.R b/R/aggregate.R index c1ba72f7e..c04df3e66 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -306,7 +306,7 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. dm = st_dimensions(x)[1:2] dm[["attribute"]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, point = any(st_dimension(g) > 0), values = dimnames(x)[[2]]), class = "dimension") - st_as_stars(list(ret), dimensions = st_dimensions(to)) + st_as_stars(list(attributes = ret), dimensions = st_dimensions(to)) } dasymetric = function(x, to, extensive, keep_NA, include_non_intersected) { From 57786263059b251ce6af2f12ada531b151b13e11 Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 15 Sep 2026 16:16:25 +0200 Subject: [PATCH 12/27] extensive --- R/aggregate.R | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/R/aggregate.R b/R/aggregate.R index c04df3e66..5a867632d 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -289,18 +289,17 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. stop("raster dimensions of to need to be at position 1 and 2; use aperm to rearrange") if (st_dimensions(to)[[2]]$delta > 0) stop("only implemented for negative N-S cellsize") - w = CPL_grid_intersection_fractions(c(st_bbox(to), dim(to)), st_geometry(x)) + w = CPL_grid_intersection_fractions(c(st_bbox(to), dim(to)), st_geometry(x)) # n_cells x n_geoms g = st_geometry(x) - x = as.matrix(st_set_geometry(x, NULL)) - ret = w %*% x - rs = rowSums(w) - ret = if (extensive) { - areas = rep(st_area(g), each = ncol(w)) - cellsize = st_area(to) - ret * units::drop_units(cellsize / areas) + x = as.matrix(st_set_geometry(x, NULL)) # n_geoms x n_attributes + if (extensive) { + cellsize = units::drop_units(st_area(to)[[1]][1,1]) + ret = w %*% (x / st_area(g)) * cellsize # n_cells x n_attributes } else { + ret = w %*% x # n_cells x n_attributes + rs = rowSums(w) ret[rs == 0.0] = NA - ret / rs + ret = ret / rs } dim(ret) = c(dim(to)[1:2], ncol(x)) dm = st_dimensions(x)[1:2] From 535f3b7c4ebd82142916a6895bcaa067ad94e2ab Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 15 Sep 2026 16:32:18 +0200 Subject: [PATCH 13/27] extensive --- R/aggregate.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/aggregate.R b/R/aggregate.R index 5a867632d..06d470794 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -292,12 +292,13 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. w = CPL_grid_intersection_fractions(c(st_bbox(to), dim(to)), st_geometry(x)) # n_cells x n_geoms g = st_geometry(x) x = as.matrix(st_set_geometry(x, NULL)) # n_geoms x n_attributes + rs = rowSums(w) if (extensive) { - cellsize = units::drop_units(st_area(to)[[1]][1,1]) + cellsize = mean(units::drop_units(st_area(to)[[1]])) ret = w %*% (x / st_area(g)) * cellsize # n_cells x n_attributes + ret[rs == 0.0] = NA } else { ret = w %*% x # n_cells x n_attributes - rs = rowSums(w) ret[rs == 0.0] = NA ret = ret / rs } From a263ddc9ea80c99fa7d45c6d6bdb20870f402c37 Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 15 Sep 2026 19:12:46 +0200 Subject: [PATCH 14/27] use cell area --- R/aggregate.R | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/R/aggregate.R b/R/aggregate.R index 06d470794..caaa8ee81 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -293,16 +293,22 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. g = st_geometry(x) x = as.matrix(st_set_geometry(x, NULL)) # n_geoms x n_attributes rs = rowSums(w) - if (extensive) { - cellsize = mean(units::drop_units(st_area(to)[[1]])) - ret = w %*% (x / st_area(g)) * cellsize # n_cells x n_attributes - ret[rs == 0.0] = NA - } else { - ret = w %*% x # n_cells x n_attributes + ret = if (extensive) { + cellsize = as.vector(units::drop_units(st_area(to)[[1]])) + w %*% (x / st_area(g)) * cellsize # n_cells x n_attributes + } else + w %*% x # n_cells x n_attributes + + if (ncol(x) > 1) + ret[rs == 0.0,] = NA + else ret[rs == 0.0] = NA + + if (!extensive) ret = ret / rs - } + dim(ret) = c(dim(to)[1:2], ncol(x)) + dm = st_dimensions(x)[1:2] dm[["attribute"]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, point = any(st_dimension(g) > 0), values = dimnames(x)[[2]]), class = "dimension") From 6ff58c7a2d262cee13da35cbab4fa589a169b16e Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 15 Sep 2026 19:17:44 +0200 Subject: [PATCH 15/27] fix dimensions --- R/aggregate.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/aggregate.R b/R/aggregate.R index caaa8ee81..43f588d06 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -309,7 +309,7 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. dim(ret) = c(dim(to)[1:2], ncol(x)) - dm = st_dimensions(x)[1:2] + dm = st_dimensions(to)[1:2] dm[["attribute"]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, point = any(st_dimension(g) > 0), values = dimnames(x)[[2]]), class = "dimension") st_as_stars(list(attributes = ret), dimensions = st_dimensions(to)) From 0c3d686ff5829e55a04ed8d9ab64ff5979ab7fbd Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 16 Sep 2026 00:55:30 +0200 Subject: [PATCH 16/27] fix dimension --- R/aggregate.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/aggregate.R b/R/aggregate.R index 43f588d06..8b5a73d25 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -310,8 +310,9 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. dim(ret) = c(dim(to)[1:2], ncol(x)) dm = st_dimensions(to)[1:2] - dm[["attribute"]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, - point = any(st_dimension(g) > 0), values = dimnames(x)[[2]]), class = "dimension") + dm[["attribute"]] = structure(list(from = 1L, to = ncol(x), offset = NA_real_, delta = NA_real_, + refsys = NA_character_, point = any(st_dimension(g) > 0), + values = dimnames(x)[[2]]), class = "dimension") st_as_stars(list(attributes = ret), dimensions = st_dimensions(to)) } From 68598c0fa9ebe059ac6e397a32bde116c145d222 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 16 Sep 2026 00:59:31 +0200 Subject: [PATCH 17/27] set dimensions --- R/aggregate.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/aggregate.R b/R/aggregate.R index 8b5a73d25..3fd0739f3 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -313,7 +313,7 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. dm[["attribute"]] = structure(list(from = 1L, to = ncol(x), offset = NA_real_, delta = NA_real_, refsys = NA_character_, point = any(st_dimension(g) > 0), values = dimnames(x)[[2]]), class = "dimension") - st_as_stars(list(attributes = ret), dimensions = st_dimensions(to)) + st_as_stars(list(attributes = ret), dimensions = dm) } dasymetric = function(x, to, extensive, keep_NA, include_non_intersected) { From 6bf471db126027a5cdc7e7c4894fa16b8f87df14 Mon Sep 17 00:00:00 2001 From: Edzer Pebesma Date: Wed, 16 Sep 2026 13:44:24 +0200 Subject: [PATCH 18/27] Update src/geos.cpp Co-authored-by: Dan Baston --- src/geos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geos.cpp b/src/geos.cpp index 776f7e449..a37577cd3 100644 --- a/src/geos.cpp +++ b/src/geos.cpp @@ -1621,7 +1621,7 @@ Rcpp::NumericVector CPL_grid_intersection_fractions(Rcpp::NumericVector p, Rcpp: int dim = 2; unsigned ncell = p[4] * p[5]; std::vector g = geometries_from_sfc(hGEOSCtxt, geoms, &dim); - std::vector buf(ncell); // nx * ny * n.geoms + std::vector buf(ncell); // nx * ny Rcpp::NumericVector ret(ncell * g.size()); for (int i = 0; i < (int) g.size(); i++) { for (int j = 0; j < ncell; j++) From 7fe6b3e2a46d24fff744bef0e85e0bb0f05703dc Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 16 Sep 2026 14:18:54 +0200 Subject: [PATCH 19/27] drop units --- R/aggregate.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/aggregate.R b/R/aggregate.R index 3fd0739f3..34b2bc0a1 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -294,7 +294,9 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. x = as.matrix(st_set_geometry(x, NULL)) # n_geoms x n_attributes rs = rowSums(w) ret = if (extensive) { - cellsize = as.vector(units::drop_units(st_area(to)[[1]])) + cellsize = as.vector(st_area(to)[[1]]) + if (inherits(cellsize, "units")) + cellsize = units::drop_units(cellsize) w %*% (x / st_area(g)) * cellsize # n_cells x n_attributes } else w %*% x # n_cells x n_attributes From 5025851cda4fd77e35bea01505159b1ff2a5d2a5 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 16 Sep 2026 23:45:59 +0200 Subject: [PATCH 20/27] tidy; add warnings; --- NEWS.md | 6 ++++++ R/aggregate.R | 33 ++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/NEWS.md b/NEWS.md index f5675de83..96116ac5f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# version 1.1-4 + +* optimize `st_interpolate_aw()` for regular gridded source or +target geometries using `GEOS::GEOSGridIntersectionFractions()` +(requiring GEOS >= 3.14); #2624 + # version 1.1-3 * move `st_interpolate_aw.stars()` from `stars` to `sf`, to get ready for using `GEOS::GEOSGridIntersectionFractions()` in the future diff --git a/R/aggregate.R b/R/aggregate.R index 34b2bc0a1..f61d4317b 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -158,7 +158,7 @@ st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = if (inherits(to, "stars") && length(weights) == 0) { if (! requireNamespace("stars", quietly = TRUE)) stop("package stars required, please install it first") - if (st_raster_type(to) == "regular" && + if (stars::st_raster_type(to) == "regular" && compareVersion(gsub("[a-zA-Z].+$", "", sf_extSoftVersion()[["GEOS"]]), "3.14.0") > -1) { return(interpolate_aw_sf_stars(x, to, extensive, ..., keep_NA = keep_NA, na.rm = na.rm, include_non_intersected = include_non_intersected)) @@ -174,7 +174,7 @@ st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = x = x[! apply(is.na(x), 1, any),] if (length(weights)) { - stopifnot(length(weights) == 1, is.character(weights), inherits(to, "sf"), weights %in% names(to)) + stopifnot(length(weights) == 1, is.character(weights), inherits(to, c("sf", "stars")), weights %in% names(to)) return(dasymetric(x, to[weights], extensive, keep_NA, include_non_intersected)) } @@ -225,11 +225,16 @@ st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = #' @name interpolate_aw #' @export st_interpolate_aw.stars = function(x, to, extensive, ...) { + if (! requireNamespace("stars", quietly = TRUE)) stop("package stars required, please install it first") - if (st_raster_type(x) == "regular" && + stopifnot(st_crs(x) == st_crs(to)) + + if (stars::st_raster_type(x) == "regular" && compareVersion(gsub("[a-zA-Z].+$", "", sf_extSoftVersion()[["GEOS"]]), "3.14.0") > -1) { + if (isTRUE(st_is_longlat(x))) + warning("for longitude/latitude data and gridded geometry, st_interpolate_aw computes intersections assuming Cartesian coordinates; use st_as_sf(x) if this is unwanted") # we HAVE_GEOS_3_14_0 if (!inherits(to, "sf") && !inherits(to, "sfc")) { # the stars-stars is for another day to <- try(st_as_sf(to)) @@ -237,9 +242,9 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { stop("st_interpolate_aw requires geometries in argument to") } # check x and y are first two dimensions: - if (!identical(match(attr(st_dimensions(x), "raster")$dimensions, names(dim(x))), 1:2)) + if (!identical(match(attr(stars::st_dimensions(x), "raster")$dimensions, names(dim(x))), 1:2)) stop("raster dimensions need to be at position 1 and 2; use aperm to rearrange") - if (st_dimensions(x)[[2]]$delta > 0) + if (stars::st_dimensions(x)[[2]]$delta > 0) stop("only implemented for negative N-S cellsize") w = CPL_grid_intersection_fractions(c(st_bbox(x), dim(x)), st_geometry(to)) weight = function(a, w, extensive) { @@ -255,14 +260,14 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { ret } ret = lapply(x, weight, w, extensive) - dm = st_dimensions(x) + dm = stars::st_dimensions(x) dm[[1]] = NULL attr(dm, "raster")$dimensions = c(NA_character_, NA_character_) g = st_geometry(to) dm[[1]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, refsys = st_crs(g), point = any(st_dimension(g) > 0), values = g), class = "dimension") names(dm)[1] = "geometry" - st_as_stars(ret, dimensions = dm) + stars::st_as_stars(ret, dimensions = dm) } else { # convert stars to sf... ret = st_interpolate_aw(st_as_sf(x), to, extensive, ...) geom = attr(ret, "sf_column") @@ -281,13 +286,15 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na.rm = na.rm, include_non_intersected = include_non_intersected) { - # st_interpolate_aw(x, st_as_sf(to), extensive, ...) + # todo: deal with include_non_intersected... + stopifnot(inherits(to, "stars"), inherits(x, "sf"), st_crs(x) == st_crs(to)) + if (isTRUE(st_is_longlat(x))) + warning("for longitude/latitude data and gridded geometry, st_interpolate_aw computes intersections assuming Cartesian coordinates; use st_as_sf(to) if this is unwanted") - stopifnot(inherits(to, "stars"), inherits(x, "sf")) # check x and y are first two dimensions: - if (!identical(match(attr(st_dimensions(to), "raster")$dimensions, names(dim(to))), 1:2)) + if (!identical(match(attr(stars::st_dimensions(to), "raster")$dimensions, names(dim(to))), 1:2)) stop("raster dimensions of to need to be at position 1 and 2; use aperm to rearrange") - if (st_dimensions(to)[[2]]$delta > 0) + if (stars::st_dimensions(to)[[2]]$delta > 0) stop("only implemented for negative N-S cellsize") w = CPL_grid_intersection_fractions(c(st_bbox(to), dim(to)), st_geometry(x)) # n_cells x n_geoms g = st_geometry(x) @@ -311,11 +318,11 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. dim(ret) = c(dim(to)[1:2], ncol(x)) - dm = st_dimensions(to)[1:2] + dm = stars::st_dimensions(to)[1:2] dm[["attribute"]] = structure(list(from = 1L, to = ncol(x), offset = NA_real_, delta = NA_real_, refsys = NA_character_, point = any(st_dimension(g) > 0), values = dimnames(x)[[2]]), class = "dimension") - st_as_stars(list(attributes = ret), dimensions = dm) + stars::st_as_stars(list(attributes = ret), dimensions = dm) } dasymetric = function(x, to, extensive, keep_NA, include_non_intersected) { From 7094fc0720f557d050ba56737cbc55ecdf89c644 Mon Sep 17 00:00:00 2001 From: edzer Date: Thu, 17 Sep 2026 23:02:50 +0200 Subject: [PATCH 21/27] move warning --- R/aggregate.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/aggregate.R b/R/aggregate.R index f61d4317b..a7190ac57 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -152,9 +152,6 @@ st_interpolate_aw = function(x, to, extensive, ...) UseMethod("st_interpolate_aw st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = FALSE, include_non_intersected = FALSE, weights = character(0)) { - if (! all_constant(x)) - warning("st_interpolate_aw assumes attributes are constant or uniform over areas of x") - if (inherits(to, "stars") && length(weights) == 0) { if (! requireNamespace("stars", quietly = TRUE)) stop("package stars required, please install it first") @@ -165,6 +162,9 @@ st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = } } + if (! all_constant(x)) + warning("st_interpolate_aw assumes attributes are constant or uniform over areas of x") + if (!inherits(to, "sf") && !inherits(to, "sfc")) { to <- try(st_as_sf(to)) if (inherits(to, "try-error")) From f1061502adc6f9b08bfde91e18d80ef26ad8419f Mon Sep 17 00:00:00 2001 From: edzer Date: Mon, 28 Sep 2026 08:28:25 +0200 Subject: [PATCH 22/27] update aw interpolation --- R/aggregate.R | 16 +++++++++------- man/interpolate_aw.Rd | 12 +++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/R/aggregate.R b/R/aggregate.R index a7190ac57..d17b58f65 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -90,13 +90,13 @@ aggregate.sf = function(x, by, FUN, ..., do_union = TRUE, simplify = TRUE, } } -#' Area-weighted interpolation or dasymetric mapping of polygon data +#' Area-weighted interpolation (conservative regridding) or dasymetric mapping #' -#' Area-weighted interpolation or dasymetric mapping of polygon data +#' Area-weighted interpolation (conservative regridding) or dasymetric mapping #' @name interpolate_aw -#' @param x object of class \code{sf}, for which we want to aggregate attributes -#' @param to object of class \code{sf} or \code{sfc}, with the target geometries -#' @param extensive logical; if TRUE, the attribute variables are assumed to be spatially extensive (like population) and the sum is preserved, otherwise, spatially intensive (like population density) and the mean is preserved. +#' @param x object of class \code{sf} or \code{stars}, for which we want to aggregate attributes +#' @param to object of class \code{sf}, \code{sfc} or \code{stars}, with the target geometries +#' @param extensive logical; if TRUE, the attribute variables are assumed to be spatially extensive (like population) and their sum is preserved, otherwise, spatially intensive (like population density) and their mean is preserved. #' @param na.rm logical; if `TRUE` remove features with `NA` attributes from `x` before interpolating #' @param ... ignored #' @param keep_NA logical; if \code{TRUE}, return all features in \code{to}, if \code{FALSE} return only those with non-NA values (but with \code{row.names} the index corresponding to the feature in \code{to}) @@ -104,6 +104,8 @@ aggregate.sf = function(x, by, FUN, ..., do_union = TRUE, simplify = TRUE, #' when `FALSE` divide by the sum of the source areas. #' @param weights character; name of column in `to` that indicates (extensive) weights, to be used instead of areas, for redistributing attributes in `x`; currently only works for `extensive=TRUE`. #' @details if `extensive` is `TRUE` and `na.rm` is set to `TRUE`, geometries with `NA` are effectively treated as having zero attribute values. Dasymetric mapping is obtained when `weights` are specified. +#' +#' Handling of gridded data (\code{stars} objects) is efficient when GEOS >= 3.14 #' @examples #' # example Area-weighted interpolation: #' nc = st_read(system.file("shape/nc.shp", package="sf")) @@ -152,7 +154,7 @@ st_interpolate_aw = function(x, to, extensive, ...) UseMethod("st_interpolate_aw st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = FALSE, include_non_intersected = FALSE, weights = character(0)) { - if (inherits(to, "stars") && length(weights) == 0) { + if (inherits(to, "stars") && length(weights) == 0) { # use S7 multiple dispatch instead? if (! requireNamespace("stars", quietly = TRUE)) stop("package stars required, please install it first") if (stars::st_raster_type(to) == "regular" && @@ -165,7 +167,7 @@ st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = if (! all_constant(x)) warning("st_interpolate_aw assumes attributes are constant or uniform over areas of x") - if (!inherits(to, "sf") && !inherits(to, "sfc")) { + if (!inherits(to, c("sf", "sfc"))) { to <- try(st_as_sf(to)) if (inherits(to, "try-error")) stop("st_interpolate_aw requires geometries in argument to") diff --git a/man/interpolate_aw.Rd b/man/interpolate_aw.Rd index 8db2c8ae1..e4b4482d3 100644 --- a/man/interpolate_aw.Rd +++ b/man/interpolate_aw.Rd @@ -5,7 +5,7 @@ \alias{st_interpolate_aw} \alias{st_interpolate_aw.sf} \alias{st_interpolate_aw.stars} -\title{Area-weighted interpolation or dasymetric mapping of polygon data} +\title{Area-weighted interpolation (conservative regridding) or dasymetric mapping} \usage{ st_interpolate_aw(x, to, extensive, ...) @@ -23,11 +23,11 @@ st_interpolate_aw(x, to, extensive, ...) \method{st_interpolate_aw}{stars}(x, to, extensive, ...) } \arguments{ -\item{x}{object of class \code{sf}, for which we want to aggregate attributes} +\item{x}{object of class \code{sf} or \code{stars}, for which we want to aggregate attributes} -\item{to}{object of class \code{sf} or \code{sfc}, with the target geometries} +\item{to}{object of class \code{sf}, \code{sfc} or \code{stars}, with the target geometries} -\item{extensive}{logical; if TRUE, the attribute variables are assumed to be spatially extensive (like population) and the sum is preserved, otherwise, spatially intensive (like population density) and the mean is preserved.} +\item{extensive}{logical; if TRUE, the attribute variables are assumed to be spatially extensive (like population) and their sum is preserved, otherwise, spatially intensive (like population density) and their mean is preserved.} \item{...}{ignored} @@ -41,10 +41,12 @@ when \code{FALSE} divide by the sum of the source areas.} \item{weights}{character; name of column in \code{to} that indicates (extensive) weights, to be used instead of areas, for redistributing attributes in \code{x}; currently only works for \code{extensive=TRUE}.} } \description{ -Area-weighted interpolation or dasymetric mapping of polygon data +Area-weighted interpolation (conservative regridding) or dasymetric mapping } \details{ if \code{extensive} is \code{TRUE} and \code{na.rm} is set to \code{TRUE}, geometries with \code{NA} are effectively treated as having zero attribute values. Dasymetric mapping is obtained when \code{weights} are specified. + +Handling of gridded data (\code{stars} objects) is efficient when GEOS >= 3.14 } \examples{ # example Area-weighted interpolation: From 54147fef925aba9fdce1b46bbc2c706e1ea9ddb1 Mon Sep 17 00:00:00 2001 From: edzer Date: Mon, 19 Oct 2026 09:42:40 +0200 Subject: [PATCH 23/27] add last 4; #2632 --- NEWS.md | 2 +- R/tidyverse-vctrs.R | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index af0ba895e..560c09e5a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ * optimize `st_interpolate_aw()` for regular gridded source or target geometries using `GEOS::GEOSGridIntersectionFractions()` (requiring GEOS >= 3.14); #2624 -* add `TIN`, `POLYHEDRALSURFACE` and `TRIANGLE` to vctrs methods; #2632 +* add `TIN`, `POLYHEDRALSURFACE`, `TRIANGLE`, `CIRCULARSTRING`, `COMPOUNDCURVE`, `CURVE`, and `MULTICURVE` to vctrs methods; #2632 * `st_combine()` preserves the precision of input object; #2618 diff --git a/R/tidyverse-vctrs.R b/R/tidyverse-vctrs.R index 80839792d..2481f3fd2 100644 --- a/R/tidyverse-vctrs.R +++ b/R/tidyverse-vctrs.R @@ -1,7 +1,8 @@ -types = c("POINT", "MULTIPOINT", "LINESTRING", "MULTILINESTRING", +types = c("POINT", "MULTIPOINT", "LINESTRING", "MULTILINESTRING", "POLYGON", "MULTIPOLYGON", "GEOMETRYCOLLECTION", "GEOMETRY", "MULTISURFACE", "CURVEPOLYGON", "TIN", "POLYHEDRALSURFACE", - "TRIANGLE") + "TRIANGLE", "CIRCULARSTRING", "COMPOUNDCURVE", "CURVE", + "MULTICURVE") sfc_types = paste0("sfc_", types) # All S3 methods in this file are registered lazily when vctrs is loaded From 2337a0517ae7cc3bdbcf9fe08fcd196d42d19d6c Mon Sep 17 00:00:00 2001 From: edzer Date: Mon, 19 Oct 2026 22:13:58 +0200 Subject: [PATCH 24/27] add fast raster-raster (stars) st_interpolate_aw path --- NEWS.md | 2 +- R/aggregate.R | 72 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/NEWS.md b/NEWS.md index 560c09e5a..b72019340 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # version 1.1-4 -* optimize `st_interpolate_aw()` for regular gridded source or target geometries using `GEOS::GEOSGridIntersectionFractions()` (requiring GEOS >= 3.14); #2624 +* optimize `st_interpolate_aw()` for regular gridded source or target geometries using `GEOS::GEOSGridIntersectionFractions()` (requiring GEOS >= 3.14); #2624, and also for the case where both `x` and `to` are regular or rectilinear (`stars`) rasters * add `TIN`, `POLYHEDRALSURFACE`, `TRIANGLE`, `CIRCULARSTRING`, `COMPOUNDCURVE`, `CURVE`, and `MULTICURVE` to vctrs methods; #2632 diff --git a/R/aggregate.R b/R/aggregate.R index d17b58f65..489c1f73c 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -224,50 +224,71 @@ st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = st_set_agr(df, "aggregate") } +# compute the intersection fraction (of a) of pairs of stars raster cells +intersection_fraction = function(st_a, st_b) { + ord = function(d) { + xo = if (d[[1]]$delta < 0) c(3,1) else c(1,3) # x-order small-large + yo = if (d[[2]]$delta < 0) c(4,2) else c(2,4) # y-order small-large + c(xo, yo) + } + a = st_coordinates(st_a, add_max = TRUE)[, ord(da <- st_dimensions(st_a))] + b = st_coordinates(st_b, add_max = TRUE)[, ord(st_dimensions(st_b))] + i = rep(seq_len(nrow(a)), nrow(b)) + j = rep(seq_len(nrow(b)), each = nrow(a)) + ovx = ifelse(a[i,1] > b[j,2] | a[i,2] < b[j,1], 0, pmin(a[i,2], b[j,2])- pmax(a[i,1],b[j,1])) + ovy = ifelse(a[i,3] > b[j,4] | a[i,4] < b[j,3], 0, pmin(a[i,4], b[j,4])- pmax(a[i,3],b[j,3])) + matrix(ovx * ovy, nrow(a), nrow(b)) / abs(da[[1]]$delta * da[[2]]$delta) # / cellsize(st_a) +} + + #' @name interpolate_aw #' @export st_interpolate_aw.stars = function(x, to, extensive, ...) { - if (! requireNamespace("stars", quietly = TRUE)) stop("package stars required, please install it first") stopifnot(st_crs(x) == st_crs(to)) - if (stars::st_raster_type(x) == "regular" && + weigh = function(a, w, extensive) { + d = dim(a) + dim(a) = c(prod(d[1:2]), prod(d[-(1:2)])) + ret = structure(t(w) %*% a, dim = c(ncol(w), ifelse(length(d) <= 2, 1, d[-(1:2)]))) + cs = colSums(w) + ret[cs == 0.,] = NA + if (! extensive) + ret = ret / cs + ret + } + + if (inherits(to, "stars") && stars::st_raster_type(to) %in% c("regular", "rectilinear") && + stars::st_raster_type(x) %in% c("regular", "rectilinear")) { + w = intersection_fraction(x, to) + ret = lapply(x, weigh, w, extensive) + ret = lapply(ret, structure, dim = dim(to)) + stars::st_as_stars(ret, dimensions = st_dimensions(to)) + } else if (stars::st_raster_type(x) == "regular" && compareVersion(gsub("[a-zA-Z].+$", "", sf_extSoftVersion()[["GEOS"]]), "3.14.0") > -1) { if (isTRUE(st_is_longlat(x))) - warning("for longitude/latitude data and gridded geometry, st_interpolate_aw computes intersections assuming Cartesian coordinates; use st_as_sf(x) if this is unwanted") + warning("for longitude/latitude data and gridded geometry, st_interpolate_aw computes intersections assuming Cartesian coordinates; use st_as_sf(x) if this is not wanted") + # check x and y are first two dimensions: + if (!identical(match(attr(stars::st_dimensions(x), "raster")$dimensions, names(dim(x))), 1:2)) + stop("raster dimensions need to be at position 1 and 2; use aperm to rearrange") # we HAVE_GEOS_3_14_0 if (!inherits(to, "sf") && !inherits(to, "sfc")) { # the stars-stars is for another day to <- try(st_as_sf(to)) if (inherits(to, "try-error")) stop("st_interpolate_aw requires geometries in argument to") } - # check x and y are first two dimensions: - if (!identical(match(attr(stars::st_dimensions(x), "raster")$dimensions, names(dim(x))), 1:2)) - stop("raster dimensions need to be at position 1 and 2; use aperm to rearrange") if (stars::st_dimensions(x)[[2]]$delta > 0) stop("only implemented for negative N-S cellsize") - w = CPL_grid_intersection_fractions(c(st_bbox(x), dim(x)), st_geometry(to)) - weight = function(a, w, extensive) { - d = dim(a) - dim(a) = c(prod(d[1:2]), prod(d[-(1:2)])) - ret = t(w) %*% a - if (!extensive) { - cs = colSums(w) - cs[cs == 0] = 1 - ret = ret / cs - } - dim(ret) = c(ncol(w), d[-(1:2)]) - ret - } - ret = lapply(x, weight, w, extensive) + w = CPL_grid_intersection_fractions(c(st_bbox(x), dim(x)[1:2]), st_geometry(to)) + ret = lapply(x, weigh, w, extensive) dm = stars::st_dimensions(x) dm[[1]] = NULL attr(dm, "raster")$dimensions = c(NA_character_, NA_character_) g = st_geometry(to) dm[[1]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, - refsys = st_crs(g), point = any(st_dimension(g) > 0), values = g), class = "dimension") + refsys = st_crs(g), point = any(st_dimension(g) > 0), values = g), class = "dimension") names(dm)[1] = "geometry" stars::st_as_stars(ret, dimensions = dm) } else { # convert stars to sf... @@ -309,15 +330,12 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. w %*% (x / st_area(g)) * cellsize # n_cells x n_attributes } else w %*% x # n_cells x n_attributes - - if (ncol(x) > 1) - ret[rs == 0.0,] = NA - else - ret[rs == 0.0] = NA - + dim(ret) = c(nrow(w), ncol(x)) # needed for the case of ncol(x) == 1 + ret[rs == 0.0, ] = NA if (!extensive) ret = ret / rs + # redimension: dim(ret) = c(dim(to)[1:2], ncol(x)) dm = stars::st_dimensions(to)[1:2] From a1df089fbbc7dd8e85472dc38f15fa59ad047919 Mon Sep 17 00:00:00 2001 From: edzer Date: Mon, 19 Oct 2026 22:20:33 +0200 Subject: [PATCH 25/27] tidy --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index b72019340..acf899c91 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # version 1.1-4 -* optimize `st_interpolate_aw()` for regular gridded source or target geometries using `GEOS::GEOSGridIntersectionFractions()` (requiring GEOS >= 3.14); #2624, and also for the case where both `x` and `to` are regular or rectilinear (`stars`) rasters +* optimize `st_interpolate_aw()` for regular gridded source xor target geometries using `GEOS::GEOSGridIntersectionFractions()` (requiring GEOS >= 3.14); #2624, and also for the case where both `x` and `to` are regular or rectilinear (`stars`) rasters * add `TIN`, `POLYHEDRALSURFACE`, `TRIANGLE`, `CIRCULARSTRING`, `COMPOUNDCURVE`, `CURVE`, and `MULTICURVE` to vctrs methods; #2632 From 66b12b042470888c8c2fd7d80c37f7410257bc00 Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 10 Nov 2026 21:34:08 +0100 Subject: [PATCH 26/27] changes due to new autoconf version --- configure | 594 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 327 insertions(+), 267 deletions(-) diff --git a/configure b/configure index 4e3d406c5..5e99a8739 100755 --- a/configure +++ b/configure @@ -1,9 +1,9 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.71. +# Generated by GNU Autoconf 2.72. # # -# Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation, +# Copyright (C) 1992-1996, 1998-2017, 2020-2023 Free Software Foundation, # Inc. # # @@ -15,7 +15,6 @@ # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh -as_nop=: if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 then : emulate sh @@ -24,12 +23,13 @@ then : # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST -else $as_nop - case `(set -o) 2>/dev/null` in #( +else case e in #( + e) case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; +esac ;; esac fi @@ -101,7 +101,7 @@ IFS=$as_save_IFS ;; esac -# We did not find ourselves, most probably we were run as `sh COMMAND' +# We did not find ourselves, most probably we were run as 'sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 @@ -131,15 +131,14 @@ case $- in # (((( esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. +# out after a failed 'exec'. printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then - as_bourne_compatible="as_nop=: -if test \${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 + as_bourne_compatible="if test \${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 then : emulate sh NULLCMD=: @@ -147,12 +146,13 @@ then : # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST -else \$as_nop - case \`(set -o) 2>/dev/null\` in #( +else case e in #( + e) case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; +esac ;; esac fi " @@ -170,8 +170,9 @@ as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ) then : -else \$as_nop - exitcode=1; echo positional parameters were not saved. +else case e in #( + e) exitcode=1; echo positional parameters were not saved. ;; +esac fi test x\$exitcode = x0 || exit 1 blah=\$(echo \$(echo blah)) @@ -184,14 +185,15 @@ test -x / || exit 1" if (eval "$as_required") 2>/dev/null then : as_have_required=yes -else $as_nop - as_have_required=no +else case e in #( + e) as_have_required=no ;; +esac fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null then : -else $as_nop - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +else case e in #( + e) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do @@ -224,12 +226,13 @@ IFS=$as_save_IFS if $as_found then : -else $as_nop - if { test -f "$SHELL" || test -f "$SHELL.exe"; } && +else case e in #( + e) if { test -f "$SHELL" || test -f "$SHELL.exe"; } && as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null then : CONFIG_SHELL=$SHELL as_have_required=yes -fi +fi ;; +esac fi @@ -251,7 +254,7 @@ case $- in # (((( esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. +# out after a failed 'exec'. printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi @@ -270,7 +273,8 @@ $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 -fi +fi ;; +esac fi fi SHELL=${CONFIG_SHELL-/bin/sh} @@ -309,14 +313,6 @@ as_fn_exit () as_fn_set_status $1 exit $1 } # as_fn_exit -# as_fn_nop -# --------- -# Do nothing but, unlike ":", preserve the value of $?. -as_fn_nop () -{ - return $? -} -as_nop=as_fn_nop # as_fn_mkdir_p # ------------- @@ -385,11 +381,12 @@ then : { eval $1+=\$2 }' -else $as_nop - as_fn_append () +else case e in #( + e) as_fn_append () { eval $1=\$$1\$2 - } + } ;; +esac fi # as_fn_append # as_fn_arith ARG... @@ -403,21 +400,14 @@ then : { as_val=$(( $* )) }' -else $as_nop - as_fn_arith () +else case e in #( + e) as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` - } + } ;; +esac fi # as_fn_arith -# as_fn_nop -# --------- -# Do nothing but, unlike ":", preserve the value of $?. -as_fn_nop () -{ - return $? -} -as_nop=as_fn_nop # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- @@ -491,6 +481,8 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits /[$]LINENO/= ' <$as_myself | sed ' + t clear + :clear s/[$]LINENO.*/&-/ t lineno b @@ -539,7 +531,6 @@ esac as_echo='printf %s\n' as_echo_n='printf %s' - rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file @@ -551,9 +542,9 @@ if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: - # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. - # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # 1) On MSYS, both 'ln -s file dir' and 'ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; 'ln -s' creates a wrapper executable. + # In both cases, we have to default to 'cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then @@ -578,10 +569,12 @@ as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. -as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" +as_sed_cpp="y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g" +as_tr_cpp="eval sed '$as_sed_cpp'" # deprecated # Sed expression to map a string onto a valid variable name. -as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" +as_sed_sh="y%*+%pp%;s%[^_$as_cr_alnum]%_%g" +as_tr_sh="eval sed '$as_sed_sh'" # deprecated test -n "$DJDIR" || exec 7<&0 /dev/null && - as_fn_error $? "invalid feature name: \`$ac_useropt'" + as_fn_error $? "invalid feature name: '$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in @@ -855,7 +848,7 @@ do ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid feature name: \`$ac_useropt'" + as_fn_error $? "invalid feature name: '$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in @@ -1068,7 +1061,7 @@ do ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid package name: \`$ac_useropt'" + as_fn_error $? "invalid package name: '$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in @@ -1084,7 +1077,7 @@ do ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid package name: \`$ac_useropt'" + as_fn_error $? "invalid package name: '$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in @@ -1114,8 +1107,8 @@ do | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; - -*) as_fn_error $? "unrecognized option: \`$ac_option' -Try \`$0 --help' for more information" + -*) as_fn_error $? "unrecognized option: '$ac_option' +Try '$0 --help' for more information" ;; *=*) @@ -1123,7 +1116,7 @@ Try \`$0 --help' for more information" # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) - as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; + as_fn_error $? "invalid variable name: '$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; @@ -1173,7 +1166,7 @@ do as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done -# There might be people who depend on the old broken behavior: `$host' +# There might be people who depend on the old broken behavior: '$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias @@ -1241,7 +1234,7 @@ if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi -ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_msg="sources are in $srcdir, but 'cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` @@ -1269,7 +1262,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures this package to adapt to many kinds of systems. +'configure' configures this package to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1283,11 +1276,11 @@ Configuration: --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit - -q, --quiet, --silent do not print \`checking ...' messages + -q, --quiet, --silent do not print 'checking ...' messages --cache-file=FILE cache test results in FILE [disabled] - -C, --config-cache alias for \`--cache-file=config.cache' + -C, --config-cache alias for '--cache-file=config.cache' -n, --no-create do not create output files - --srcdir=DIR find the sources in DIR [configure dir or \`..'] + --srcdir=DIR find the sources in DIR [configure dir or '..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX @@ -1295,10 +1288,10 @@ Installation directories: --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] -By default, \`make install' will install all the files in -\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify -an installation prefix other than \`$ac_default_prefix' using \`--prefix', -for instance \`--prefix=\$HOME'. +By default, 'make install' will install all the files in +'$ac_default_prefix/bin', '$ac_default_prefix/lib' etc. You can specify +an installation prefix other than '$ac_default_prefix' using '--prefix', +for instance '--prefix=\$HOME'. For better control, use the options below. @@ -1362,7 +1355,7 @@ Some influential environment variables: CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory -Use these variables to override the choices made by `configure' or to help +Use these variables to override the choices made by 'configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider. @@ -1430,9 +1423,9 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF configure -generated by GNU Autoconf 2.71 +generated by GNU Autoconf 2.72 -Copyright (C) 2021 Free Software Foundation, Inc. +Copyright (C) 2023 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1471,11 +1464,12 @@ printf "%s\n" "$ac_try_echo"; } >&5 } && test -s conftest.$ac_objext then : ac_retval=0 -else $as_nop - printf "%s\n" "$as_me: failed program was:" >&5 +else case e in #( + e) printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - ac_retval=1 + ac_retval=1 ;; +esac fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval @@ -1494,8 +1488,8 @@ printf %s "checking for $2... " >&6; } if eval test \${$3+y} then : printf %s "(cached) " >&6 -else $as_nop - cat confdefs.h - <<_ACEOF >conftest.$ac_ext +else case e in #( + e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> @@ -1503,10 +1497,12 @@ _ACEOF if ac_fn_c_try_compile "$LINENO" then : eval "$3=yes" -else $as_nop - eval "$3=no" +else case e in #( + e) eval "$3=no" ;; +esac fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; +esac fi eval ac_res=\$$3 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 @@ -1546,11 +1542,12 @@ printf "%s\n" "$ac_try_echo"; } >&5 } then : ac_retval=0 -else $as_nop - printf "%s\n" "$as_me: failed program was:" >&5 +else case e in #( + e) printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - ac_retval=1 + ac_retval=1 ;; +esac fi # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would @@ -1586,7 +1583,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by $as_me, which was -generated by GNU Autoconf 2.71. Invocation command line was +generated by GNU Autoconf 2.72. Invocation command line was $ $0$ac_configure_args_raw @@ -1832,10 +1829,10 @@ esac printf "%s\n" "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ - || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} + || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file -See \`config.log' for more details" "$LINENO" 5; } +See 'config.log' for more details" "$LINENO" 5; } fi done @@ -1871,9 +1868,7 @@ struct stat; /* Most of the following tests are stolen from RCS 5.7 src/conf.sh. */ struct buf { int x; }; struct buf * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; +static char *e (char **p, int i) { return p[i]; } @@ -1887,6 +1882,21 @@ static char *f (char * (*g) (char **, int), char **p, ...) return s; } +/* C89 style stringification. */ +#define noexpand_stringify(a) #a +const char *stringified = noexpand_stringify(arbitrary+token=sequence); + +/* C89 style token pasting. Exercises some of the corner cases that + e.g. old MSVC gets wrong, but not very hard. */ +#define noexpand_concat(a,b) a##b +#define expand_concat(a,b) noexpand_concat(a,b) +extern int vA; +extern int vbee; +#define aye A +#define bee B +int *pvA = &expand_concat(v,aye); +int *pvbee = &noexpand_concat(v,bee); + /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not \xHH hex character constants. These do not provoke an error unfortunately, instead are silently treated @@ -1914,16 +1924,19 @@ ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]); # Test code for whether the C compiler supports C99 (global declarations) ac_c_conftest_c99_globals=' -// Does the compiler advertise C99 conformance? +/* Does the compiler advertise C99 conformance? */ #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L # error "Compiler does not advertise C99 conformance" #endif +// See if C++-style comments work. + #include extern int puts (const char *); extern int printf (const char *, ...); extern int dprintf (int, const char *, ...); extern void *malloc (size_t); +extern void free (void *); // Check varargs macros. These examples are taken from C99 6.10.3.5. // dprintf is used instead of fprintf to avoid needing to declare @@ -1973,7 +1986,6 @@ typedef const char *ccp; static inline int test_restrict (ccp restrict text) { - // See if C++-style comments work. // Iterate through items via the restricted pointer. // Also check for declarations in for loops. for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i) @@ -2039,6 +2051,8 @@ ac_c_conftest_c99_main=' ia->datasize = 10; for (int i = 0; i < ia->datasize; ++i) ia->data[i] = i * 1.234; + // Work around memory leak warnings. + free (ia); // Check named initializers. struct named_init ni = { @@ -2060,7 +2074,7 @@ ac_c_conftest_c99_main=' # Test code for whether the C compiler supports C11 (global declarations) ac_c_conftest_c11_globals=' -// Does the compiler advertise C11 conformance? +/* Does the compiler advertise C11 conformance? */ #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L # error "Compiler does not advertise C11 conformance" #endif @@ -2183,12 +2197,12 @@ for ac_var in $ac_precious_vars; do eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 -printf "%s\n" "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' was set to '$ac_old_val' in the previous run" >&5 +printf "%s\n" "$as_me: error: '$ac_var' was set to '$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 -printf "%s\n" "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' was not set in the previous run" >&5 +printf "%s\n" "$as_me: error: '$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) @@ -2197,18 +2211,18 @@ printf "%s\n" "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 -printf "%s\n" "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' has changed since the previous run:" >&5 +printf "%s\n" "$as_me: error: '$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 -printf "%s\n" "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in '$ac_var' since the previous run:" >&5 +printf "%s\n" "$as_me: warning: ignoring whitespace changes in '$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 -printf "%s\n" "$as_me: former value: \`$ac_old_val'" >&2;} - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 -printf "%s\n" "$as_me: current value: \`$ac_new_val'" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: former value: '$ac_old_val'" >&5 +printf "%s\n" "$as_me: former value: '$ac_old_val'" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: current value: '$ac_new_val'" >&5 +printf "%s\n" "$as_me: current value: '$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. @@ -2224,11 +2238,11 @@ printf "%s\n" "$as_me: current value: \`$ac_new_val'" >&2;} fi done if $ac_cache_corrupted; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;} - as_fn_error $? "run \`${MAKE-make} distclean' and/or \`rm $cache_file' + as_fn_error $? "run '${MAKE-make} distclean' and/or 'rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## @@ -2318,8 +2332,8 @@ printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_path_GDAL_CONFIG+y} then : printf %s "(cached) " >&6 -else $as_nop - case $GDAL_CONFIG in +else case e in #( + e) case $GDAL_CONFIG in [\\/]* | ?:[\\/]*) ac_cv_path_GDAL_CONFIG="$GDAL_CONFIG" # Let the user override the test with a path. ;; @@ -2345,6 +2359,7 @@ IFS=$as_save_IFS test -z "$ac_cv_path_GDAL_CONFIG" && ac_cv_path_GDAL_CONFIG=""no"" ;; +esac ;; esac fi GDAL_CONFIG=$ac_cv_path_GDAL_CONFIG @@ -2460,8 +2475,8 @@ printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 -else $as_nop - if test -n "$CC"; then +else case e in #( + e) if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -2483,7 +2498,8 @@ done done IFS=$as_save_IFS -fi +fi ;; +esac fi CC=$ac_cv_prog_CC if test -n "$CC"; then @@ -2505,8 +2521,8 @@ printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CC+y} then : printf %s "(cached) " >&6 -else $as_nop - if test -n "$ac_ct_CC"; then +else case e in #( + e) if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -2528,7 +2544,8 @@ done done IFS=$as_save_IFS -fi +fi ;; +esac fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then @@ -2563,8 +2580,8 @@ printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 -else $as_nop - if test -n "$CC"; then +else case e in #( + e) if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -2586,7 +2603,8 @@ done done IFS=$as_save_IFS -fi +fi ;; +esac fi CC=$ac_cv_prog_CC if test -n "$CC"; then @@ -2608,8 +2626,8 @@ printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 -else $as_nop - if test -n "$CC"; then +else case e in #( + e) if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no @@ -2648,7 +2666,8 @@ if test $ac_prog_rejected = yes; then ac_cv_prog_CC="$as_dir$ac_word${1+' '}$@" fi fi -fi +fi ;; +esac fi CC=$ac_cv_prog_CC if test -n "$CC"; then @@ -2672,8 +2691,8 @@ printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 -else $as_nop - if test -n "$CC"; then +else case e in #( + e) if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -2695,7 +2714,8 @@ done done IFS=$as_save_IFS -fi +fi ;; +esac fi CC=$ac_cv_prog_CC if test -n "$CC"; then @@ -2721,8 +2741,8 @@ printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CC+y} then : printf %s "(cached) " >&6 -else $as_nop - if test -n "$ac_ct_CC"; then +else case e in #( + e) if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -2744,7 +2764,8 @@ done done IFS=$as_save_IFS -fi +fi ;; +esac fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then @@ -2782,8 +2803,8 @@ printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 -else $as_nop - if test -n "$CC"; then +else case e in #( + e) if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -2805,7 +2826,8 @@ done done IFS=$as_save_IFS -fi +fi ;; +esac fi CC=$ac_cv_prog_CC if test -n "$CC"; then @@ -2827,8 +2849,8 @@ printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CC+y} then : printf %s "(cached) " >&6 -else $as_nop - if test -n "$ac_ct_CC"; then +else case e in #( + e) if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -2850,7 +2872,8 @@ done done IFS=$as_save_IFS -fi +fi ;; +esac fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then @@ -2879,10 +2902,10 @@ fi fi -test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH -See \`config.log' for more details" "$LINENO" 5; } +See 'config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 @@ -2954,8 +2977,8 @@ printf "%s\n" "$ac_try_echo"; } >&5 printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then : - # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. -# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' + # Autoconf-2.13 could set the ac_cv_exeext variable to 'no'. +# So ignore a value of 'no', otherwise this would lead to 'EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. @@ -2975,7 +2998,7 @@ do ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not - # safe: cross compilers may not add the suffix if given an `-o' + # safe: cross compilers may not add the suffix if given an '-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. @@ -2986,8 +3009,9 @@ do done test "$ac_cv_exeext" = no && ac_cv_exeext= -else $as_nop - ac_file='' +else case e in #( + e) ac_file='' ;; +esac fi if test -z "$ac_file" then : @@ -2996,13 +3020,14 @@ printf "%s\n" "no" >&6; } printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 -{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables -See \`config.log' for more details" "$LINENO" 5; } -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -printf "%s\n" "yes" >&6; } +See 'config.log' for more details" "$LINENO" 5; } +else case e in #( + e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } ;; +esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 printf %s "checking for C compiler default output file name... " >&6; } @@ -3026,10 +3051,10 @@ printf "%s\n" "$ac_try_echo"; } >&5 printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then : - # If both `conftest.exe' and `conftest' are `present' (well, observable) -# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will -# work properly (i.e., refer to `conftest.exe'), while it won't with -# `rm'. + # If both 'conftest.exe' and 'conftest' are 'present' (well, observable) +# catch 'conftest.exe'. For instance with Cygwin, 'ls conftest' will +# work properly (i.e., refer to 'conftest.exe'), while it won't with +# 'rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in @@ -3039,11 +3064,12 @@ for ac_file in conftest.exe conftest conftest.*; do * ) break;; esac done -else $as_nop - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +else case e in #( + e) { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link -See \`config.log' for more details" "$LINENO" 5; } +See 'config.log' for more details" "$LINENO" 5; } ;; +esac fi rm -f conftest conftest$ac_cv_exeext { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 @@ -3059,6 +3085,8 @@ int main (void) { FILE *f = fopen ("conftest.out", "w"); + if (!f) + return 1; return ferror (f) || fclose (f) != 0; ; @@ -3098,26 +3126,27 @@ printf "%s\n" "$ac_try_echo"; } >&5 if test "$cross_compiling" = maybe; then cross_compiling=yes else - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error 77 "cannot run C compiled programs. -If you meant to cross compile, use \`--host'. -See \`config.log' for more details" "$LINENO" 5; } +If you meant to cross compile, use '--host'. +See 'config.log' for more details" "$LINENO" 5; } fi fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 printf "%s\n" "$cross_compiling" >&6; } -rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out +rm -f conftest.$ac_ext conftest$ac_cv_exeext \ + conftest.o conftest.obj conftest.out ac_clean_files=$ac_clean_files_save { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 printf %s "checking for suffix of object files... " >&6; } if test ${ac_cv_objext+y} then : printf %s "(cached) " >&6 -else $as_nop - cat confdefs.h - <<_ACEOF >conftest.$ac_ext +else case e in #( + e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int @@ -3149,16 +3178,18 @@ then : break;; esac done -else $as_nop - printf "%s\n" "$as_me: failed program was:" >&5 +else case e in #( + e) printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 -{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile -See \`config.log' for more details" "$LINENO" 5; } +See 'config.log' for more details" "$LINENO" 5; } ;; +esac fi -rm -f conftest.$ac_cv_objext conftest.$ac_ext +rm -f conftest.$ac_cv_objext conftest.$ac_ext ;; +esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 printf "%s\n" "$ac_cv_objext" >&6; } @@ -3169,8 +3200,8 @@ printf %s "checking whether the compiler supports GNU C... " >&6; } if test ${ac_cv_c_compiler_gnu+y} then : printf %s "(cached) " >&6 -else $as_nop - cat confdefs.h - <<_ACEOF >conftest.$ac_ext +else case e in #( + e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int @@ -3187,12 +3218,14 @@ _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_compiler_gnu=yes -else $as_nop - ac_compiler_gnu=no +else case e in #( + e) ac_compiler_gnu=no ;; +esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu - + ;; +esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; } @@ -3210,8 +3243,8 @@ printf %s "checking whether $CC accepts -g... " >&6; } if test ${ac_cv_prog_cc_g+y} then : printf %s "(cached) " >&6 -else $as_nop - ac_save_c_werror_flag=$ac_c_werror_flag +else case e in #( + e) ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" @@ -3229,8 +3262,8 @@ _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_g=yes -else $as_nop - CFLAGS="" +else case e in #( + e) CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -3245,8 +3278,8 @@ _ACEOF if ac_fn_c_try_compile "$LINENO" then : -else $as_nop - ac_c_werror_flag=$ac_save_c_werror_flag +else case e in #( + e) ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -3263,12 +3296,15 @@ if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_g=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; +esac fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; +esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - ac_c_werror_flag=$ac_save_c_werror_flag + ac_c_werror_flag=$ac_save_c_werror_flag ;; +esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 printf "%s\n" "$ac_cv_prog_cc_g" >&6; } @@ -3295,8 +3331,8 @@ printf %s "checking for $CC option to enable C11 features... " >&6; } if test ${ac_cv_prog_cc_c11+y} then : printf %s "(cached) " >&6 -else $as_nop - ac_cv_prog_cc_c11=no +else case e in #( + e) ac_cv_prog_cc_c11=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -3313,25 +3349,28 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c11" != "xno" && break done rm -f conftest.$ac_ext -CC=$ac_save_CC +CC=$ac_save_CC ;; +esac fi if test "x$ac_cv_prog_cc_c11" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } -else $as_nop - if test "x$ac_cv_prog_cc_c11" = x +else case e in #( + e) if test "x$ac_cv_prog_cc_c11" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5 +else case e in #( + e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5 printf "%s\n" "$ac_cv_prog_cc_c11" >&6; } - CC="$CC $ac_cv_prog_cc_c11" + CC="$CC $ac_cv_prog_cc_c11" ;; +esac fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11 - ac_prog_cc_stdc=c11 + ac_prog_cc_stdc=c11 ;; +esac fi fi if test x$ac_prog_cc_stdc = xno @@ -3341,8 +3380,8 @@ printf %s "checking for $CC option to enable C99 features... " >&6; } if test ${ac_cv_prog_cc_c99+y} then : printf %s "(cached) " >&6 -else $as_nop - ac_cv_prog_cc_c99=no +else case e in #( + e) ac_cv_prog_cc_c99=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -3359,25 +3398,28 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c99" != "xno" && break done rm -f conftest.$ac_ext -CC=$ac_save_CC +CC=$ac_save_CC ;; +esac fi if test "x$ac_cv_prog_cc_c99" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } -else $as_nop - if test "x$ac_cv_prog_cc_c99" = x +else case e in #( + e) if test "x$ac_cv_prog_cc_c99" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 +else case e in #( + e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 printf "%s\n" "$ac_cv_prog_cc_c99" >&6; } - CC="$CC $ac_cv_prog_cc_c99" + CC="$CC $ac_cv_prog_cc_c99" ;; +esac fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99 - ac_prog_cc_stdc=c99 + ac_prog_cc_stdc=c99 ;; +esac fi fi if test x$ac_prog_cc_stdc = xno @@ -3387,8 +3429,8 @@ printf %s "checking for $CC option to enable C89 features... " >&6; } if test ${ac_cv_prog_cc_c89+y} then : printf %s "(cached) " >&6 -else $as_nop - ac_cv_prog_cc_c89=no +else case e in #( + e) ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -3405,25 +3447,28 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext -CC=$ac_save_CC +CC=$ac_save_CC ;; +esac fi if test "x$ac_cv_prog_cc_c89" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } -else $as_nop - if test "x$ac_cv_prog_cc_c89" = x +else case e in #( + e) if test "x$ac_cv_prog_cc_c89" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +else case e in #( + e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 printf "%s\n" "$ac_cv_prog_cc_c89" >&6; } - CC="$CC $ac_cv_prog_cc_c89" + CC="$CC $ac_cv_prog_cc_c89" ;; +esac fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89 - ac_prog_cc_stdc=c89 + ac_prog_cc_stdc=c89 ;; +esac fi fi @@ -3470,8 +3515,9 @@ if test "x$ac_cv_header_gdal_h" = xyes then : printf "%s\n" "#define HAVE_GDAL_H 1" >>confdefs.h -else $as_nop - gdalok=no +else case e in #( + e) gdalok=no ;; +esac fi done @@ -3739,7 +3785,7 @@ PROJ6="no" PROJH="no" if test "${proj_config_ok}" = yes; then PROJ_VERSION=`${PROJ_CONFIG} --modversion` - PROJV1=`echo "${PROJ_VERSION}" | cut -c 1` + PROJV1=`echo "${PROJ_VERSION}" | cut -d "." -f 1` if test "${PROJV1}" -ge 6; then PROJ6="yes" PROJ_CPPFLAGS="${PROJ_CPPFLAGS} -DHAVE_PROJ_H" @@ -3763,8 +3809,9 @@ if test "x$ac_cv_header_proj_h" = xyes then : printf "%s\n" "#define HAVE_PROJ_H 1" >>confdefs.h -else $as_nop - PROJH=no +else case e in #( + e) PROJH=no ;; +esac fi done @@ -3787,8 +3834,9 @@ if test "x$ac_cv_header_proj_api_h" = xyes then : printf "%s\n" "#define HAVE_PROJ_API_H 1" >>confdefs.h -else $as_nop - proj4ok=no +else case e in #( + e) proj4ok=no ;; +esac fi done @@ -3834,16 +3882,22 @@ printf %s "checking for pj_init_plus in -lproj... " >&6; } if test ${ac_cv_lib_proj_pj_init_plus+y} then : printf %s "(cached) " >&6 -else $as_nop - ac_check_lib_save_LIBS=$LIBS +else case e in #( + e) ac_check_lib_save_LIBS=$LIBS LIBS="-lproj $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -char pj_init_plus (); + builtin and then its argument prototype would still apply. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ +#ifdef __cplusplus +extern "C" +#endif +char pj_init_plus (void); int main (void) { @@ -3855,12 +3909,14 @@ _ACEOF if ac_fn_c_try_link "$LINENO" then : ac_cv_lib_proj_pj_init_plus=yes -else $as_nop - ac_cv_lib_proj_pj_init_plus=no +else case e in #( + e) ac_cv_lib_proj_pj_init_plus=no ;; +esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS +LIBS=$ac_check_lib_save_LIBS ;; +esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_proj_pj_init_plus" >&5 printf "%s\n" "$ac_cv_lib_proj_pj_init_plus" >&6; } @@ -3870,8 +3926,9 @@ then : LIBS="-lproj $LIBS" -else $as_nop - proj4ok=no +else case e in #( + e) proj4ok=no ;; +esac fi if test "${proj4ok}" = no; then @@ -4146,8 +4203,8 @@ printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_path_GEOS_CONFIG+y} then : printf %s "(cached) " >&6 -else $as_nop - case $GEOS_CONFIG in +else case e in #( + e) case $GEOS_CONFIG in [\\/]* | ?:[\\/]*) ac_cv_path_GEOS_CONFIG="$GEOS_CONFIG" # Let the user override the test with a path. ;; @@ -4173,6 +4230,7 @@ IFS=$as_save_IFS test -z "$ac_cv_path_GEOS_CONFIG" && ac_cv_path_GEOS_CONFIG=""no"" ;; +esac ;; esac fi GEOS_CONFIG=$ac_cv_path_GEOS_CONFIG @@ -4268,8 +4326,9 @@ if test "x$ac_cv_header_geos_c_h" = xyes then : printf "%s\n" "#define HAVE_GEOS_C_H 1" >>confdefs.h -else $as_nop - geosok=no +else case e in #( + e) geosok=no ;; +esac fi done @@ -4360,8 +4419,8 @@ cat >confcache <<\_ACEOF # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # -# `ac_cv_env_foo' variables (set or unset) will be overridden when -# loading this file, other *unset* `ac_cv_foo' will be assigned the +# 'ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* 'ac_cv_foo' will be assigned the # following values. _ACEOF @@ -4391,14 +4450,14 @@ printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) - # `set' does not quote correctly, so add quotes: double-quote + # 'set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) - # `set' quotes correctly as required by POSIX, so do not add quotes. + # 'set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | @@ -4462,9 +4521,7 @@ s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g t quote b any :quote -s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g -s/\[/\\&/g -s/\]/\\&/g +s/[][ `~#$^&*(){}\\|;'\''"<>?]/\\&/g s/\$/$$/g H :any @@ -4524,7 +4581,6 @@ cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh -as_nop=: if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 then : emulate sh @@ -4533,12 +4589,13 @@ then : # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST -else $as_nop - case `(set -o) 2>/dev/null` in #( +else case e in #( + e) case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; +esac ;; esac fi @@ -4610,7 +4667,7 @@ IFS=$as_save_IFS ;; esac -# We did not find ourselves, most probably we were run as `sh COMMAND' +# We did not find ourselves, most probably we were run as 'sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 @@ -4639,7 +4696,6 @@ as_fn_error () } # as_fn_error - # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. @@ -4679,11 +4735,12 @@ then : { eval $1+=\$2 }' -else $as_nop - as_fn_append () +else case e in #( + e) as_fn_append () { eval $1=\$$1\$2 - } + } ;; +esac fi # as_fn_append # as_fn_arith ARG... @@ -4697,11 +4754,12 @@ then : { as_val=$(( $* )) }' -else $as_nop - as_fn_arith () +else case e in #( + e) as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` - } + } ;; +esac fi # as_fn_arith @@ -4784,9 +4842,9 @@ if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: - # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. - # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # 1) On MSYS, both 'ln -s file dir' and 'ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; 'ln -s' creates a wrapper executable. + # In both cases, we have to default to 'cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then @@ -4867,10 +4925,12 @@ as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. -as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" +as_sed_cpp="y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g" +as_tr_cpp="eval sed '$as_sed_cpp'" # deprecated # Sed expression to map a string onto a valid variable name. -as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" +as_sed_sh="y%*+%pp%;s%[^_$as_cr_alnum]%_%g" +as_tr_sh="eval sed '$as_sed_sh'" # deprecated exec 6>&1 @@ -4886,7 +4946,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # values after options handling. ac_log=" This file was extended by $as_me, which was -generated by GNU Autoconf 2.71. Invocation command line was +generated by GNU Autoconf 2.72. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -4913,7 +4973,7 @@ _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ -\`$as_me' instantiates files and other configuration actions +'$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. @@ -4941,10 +5001,10 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ config.status -configured by $0, generated by GNU Autoconf 2.71, +configured by $0, generated by GNU Autoconf 2.72, with options \\"\$ac_cs_config\\" -Copyright (C) 2021 Free Software Foundation, Inc. +Copyright (C) 2023 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -5001,8 +5061,8 @@ do ac_cs_silent=: ;; # This is an error. - -*) as_fn_error $? "unrecognized option: \`$1' -Try \`$0 --help' for more information." ;; + -*) as_fn_error $? "unrecognized option: '$1' +Try '$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; @@ -5052,7 +5112,7 @@ do case $ac_config_target in "src/Makevars") CONFIG_FILES="$CONFIG_FILES src/Makevars" ;; - *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; + *) as_fn_error $? "invalid argument: '$ac_config_target'" "$LINENO" 5;; esac done @@ -5070,7 +5130,7 @@ fi # creating and moving files from /tmp can sometimes cause problems. # Hook for its removal unless debugging. # Note that there is a small window in which the directory will not be cleaned: -# after its creation but before its name has been assigned to `$tmp'. +# after its creation but before its name has been assigned to '$tmp'. $debug || { tmp= ac_tmp= @@ -5094,7 +5154,7 @@ ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. -# This happens for instance with `./config.status config.h'. +# This happens for instance with './config.status config.h'. if test -n "$CONFIG_FILES"; then @@ -5260,7 +5320,7 @@ do esac case $ac_mode$ac_tag in :[FHL]*:*);; - :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; + :L* | :C*:*) as_fn_error $? "invalid tag '$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac @@ -5282,19 +5342,19 @@ do -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, - # because $ac_f cannot contain `:'. + # because $ac_f cannot contain ':'. test -f "$ac_f" || case $ac_f in [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || - as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; + as_fn_error 1 "cannot find input file: '$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`printf "%s\n" "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done - # Let's still pretend it is `configure' which instantiates (i.e., don't + # Let's still pretend it is 'configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` @@ -5418,7 +5478,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 esac _ACEOF -# Neutralize VPATH when `$srcdir' = `.'. +# Neutralize VPATH when '$srcdir' = '.'. # Shell code in configure.ac might set extrasub. # FIXME: do we really want to maintain this feature? cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 @@ -5447,9 +5507,9 @@ test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable 'datarootdir' which seems to be undefined. Please make sure it is defined" >&5 -printf "%s\n" "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +printf "%s\n" "$as_me: WARNING: $ac_file contains a reference to the variable 'datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" From 44b284143de4a4fb6dc14f1ddb8288a4913c1d0b Mon Sep 17 00:00:00 2001 From: edzer Date: Thu, 19 Nov 2026 20:59:29 +0100 Subject: [PATCH 27/27] add tests and several fixes --- NEWS.md | 4 +- R/RcppExports.R | 4 +- R/aggregate.R | 72 +++++++++++++++-------- R/geom-transformers.R | 20 +++++-- src/RcppExports.cpp | 9 +-- src/geos.cpp | 11 ++-- tests/test-by-element.Rout.save | 6 +- tests/testthat/test-aw.R | 100 +++++++++++++++++++++++++++++++- 8 files changed, 179 insertions(+), 47 deletions(-) diff --git a/NEWS.md b/NEWS.md index acf899c91..4c145d851 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # version 1.1-4 -* optimize `st_interpolate_aw()` for regular gridded source xor target geometries using `GEOS::GEOSGridIntersectionFractions()` (requiring GEOS >= 3.14); #2624, and also for the case where both `x` and `to` are regular or rectilinear (`stars`) rasters +* `st_intersection()` becomes sensitive to setting `dimensions = "polygon"` (`"lines"`) to only have polygons (lines) returned, also for the planar case. + +* optimize `st_interpolate_aw()` for regular gridded source or target geometries (using `GEOS::GEOSGridIntersectionFractions()` which requires GEOS >= 3.14); #2624, and also for the case where both `x` and `to` are regular or rectilinear (`stars`) rasters * add `TIN`, `POLYHEDRALSURFACE`, `TRIANGLE`, `CIRCULARSTRING`, `COMPOUNDCURVE`, `CURVE`, and `MULTICURVE` to vctrs methods; #2632 diff --git a/R/RcppExports.R b/R/RcppExports.R index dc18f58ee..a177728b7 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -233,8 +233,8 @@ CPL_geos_voronoi <- function(sfc, env, dTolerance = 0.0, bOnlyEdges = 1L) { .Call(`_sf_CPL_geos_voronoi`, sfc, env, dTolerance, bOnlyEdges) } -CPL_geos_op2 <- function(op, sfcx, sfcy) { - .Call(`_sf_CPL_geos_op2`, op, sfcx, sfcy) +CPL_geos_op2 <- function(op, sfcx, sfcy, min_dimension = 0L) { + .Call(`_sf_CPL_geos_op2`, op, sfcx, sfcy, min_dimension) } CPL_geos_dist_by_element <- function(sfc0, sfc1, which, par) { diff --git a/R/aggregate.R b/R/aggregate.R index 489c1f73c..c0d30630b 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -212,13 +212,19 @@ st_interpolate_aw.sf = function(x, to, extensive, ..., keep_NA = FALSE, na.rm = x_st$...area_t = merge(data.frame(idx = idx[,2]), df)$area lapply(x_st, function(v) v * x_st$...area_st / x_st$...area_t) } - x_st = aggregate(x_st, list(idx[,2]), sum) - df = if (keep_NA) { - ix = rep(NA_integer_, length(to)) - ix[x_st$Group.1] = seq_along(x_st$Group.1) - st_sf(x_st[ix,], geometry = st_geometry(to)) - } else - st_sf(x_st, geometry = st_geometry(to)[x_st$Group.1], row.names = x_st$Group.1) + to.g = st_geometry(to) + if (length(x_st[[1]])) { + x_st = aggregate(x_st, list(idx[,2]), sum) # converts x_st into a data.frame + df = if (keep_NA) { + ix = rep(NA_integer_, length(to.g)) + ix[x_st$Group.1] = seq_along(x_st$Group.1) + st_sf(x_st[ix,], geometry = to.g) + } else + st_sf(x_st, geometry = to.g[x_st$Group.1], row.names = x_st$Group.1) + } else { + ix = rep(NA_integer_, length(to.g)) + df = st_sf(data.frame(x_st)[ix,], geometry = to.g) + } # clean up: df$...area_t = df$...area_st = df$...area_s = df$Group.1 = NULL st_set_agr(df, "aggregate") @@ -231,8 +237,8 @@ intersection_fraction = function(st_a, st_b) { yo = if (d[[2]]$delta < 0) c(4,2) else c(2,4) # y-order small-large c(xo, yo) } - a = st_coordinates(st_a, add_max = TRUE)[, ord(da <- st_dimensions(st_a))] - b = st_coordinates(st_b, add_max = TRUE)[, ord(st_dimensions(st_b))] + a = st_coordinates(st_a, add_max = TRUE)[, ord(da <- stars::st_dimensions(st_a))] + b = st_coordinates(st_b, add_max = TRUE)[, ord(stars::st_dimensions(st_b))] i = rep(seq_len(nrow(a)), nrow(b)) j = rep(seq_len(nrow(b)), each = nrow(a)) ovx = ifelse(a[i,1] > b[j,2] | a[i,2] < b[j,1], 0, pmin(a[i,2], b[j,2])- pmax(a[i,1],b[j,1])) @@ -240,7 +246,6 @@ intersection_fraction = function(st_a, st_b) { matrix(ovx * ovy, nrow(a), nrow(b)) / abs(da[[1]]$delta * da[[2]]$delta) # / cellsize(st_a) } - #' @name interpolate_aw #' @export st_interpolate_aw.stars = function(x, to, extensive, ...) { @@ -265,7 +270,7 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { w = intersection_fraction(x, to) ret = lapply(x, weigh, w, extensive) ret = lapply(ret, structure, dim = dim(to)) - stars::st_as_stars(ret, dimensions = st_dimensions(to)) + stars::st_as_stars(ret, dimensions = stars::st_dimensions(to)) } else if (stars::st_raster_type(x) == "regular" && compareVersion(gsub("[a-zA-Z].+$", "", sf_extSoftVersion()[["GEOS"]]), "3.14.0") > -1) { if (isTRUE(st_is_longlat(x))) @@ -274,7 +279,7 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { if (!identical(match(attr(stars::st_dimensions(x), "raster")$dimensions, names(dim(x))), 1:2)) stop("raster dimensions need to be at position 1 and 2; use aperm to rearrange") # we HAVE_GEOS_3_14_0 - if (!inherits(to, "sf") && !inherits(to, "sfc")) { # the stars-stars is for another day + if (!inherits(to, c("sf", "sfc"))) { to <- try(st_as_sf(to)) if (inherits(to, "try-error")) stop("st_interpolate_aw requires geometries in argument to") @@ -283,14 +288,23 @@ st_interpolate_aw.stars = function(x, to, extensive, ...) { stop("only implemented for negative N-S cellsize") w = CPL_grid_intersection_fractions(c(st_bbox(x), dim(x)[1:2]), st_geometry(to)) ret = lapply(x, weigh, w, extensive) - dm = stars::st_dimensions(x) - dm[[1]] = NULL - attr(dm, "raster")$dimensions = c(NA_character_, NA_character_) - g = st_geometry(to) - dm[[1]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, - refsys = st_crs(g), point = any(st_dimension(g) > 0), values = g), class = "dimension") - names(dm)[1] = "geometry" - stars::st_as_stars(ret, dimensions = dm) + if (length(dim(x)) == 2) { # return sf object + sf = st_sf(a = as.vector(ret), geom = st_geometry(to)) + names(sf)[1] = names(x)[1] + sf + } else { + dm = stars::st_dimensions(x) + dm[[1]] = NULL + attr(dm, "raster")$dimensions = c(NA_character_, NA_character_) + g = st_geometry(to) + # this is ugly, but stars does not export stars:::create_dimension(): + dm[[1]] = structure(list(from = 1L, to = length(g), offset = NA_real_, delta = NA_real_, + refsys = st_crs(g), point = any(st_dimension(g) > 0), values = g), class = "dimension") + names(dm)[1] = "geometry" + if (length(dm) == 1L) + ret = lapply(ret, function(v) structure(as.vector(v), dim = nrow(v))) + stars::st_as_stars(ret, dimensions = dm) + } } else { # convert stars to sf... ret = st_interpolate_aw(st_as_sf(x), to, extensive, ...) geom = attr(ret, "sf_column") @@ -336,17 +350,20 @@ interpolate_aw_sf_stars = function(x, to, extensive, ..., keep_NA = keep_NA, na. ret = ret / rs # redimension: - dim(ret) = c(dim(to)[1:2], ncol(x)) - dm = stars::st_dimensions(to)[1:2] - dm[["attribute"]] = structure(list(from = 1L, to = ncol(x), offset = NA_real_, delta = NA_real_, + if (ncol(x) > 1) { + dim(ret) = c(dim(to)[1:2], ncol(x)) + dm[["attribute"]] = structure(list(from = 1L, to = ncol(x), offset = NA_real_, delta = NA_real_, refsys = NA_character_, point = any(st_dimension(g) > 0), values = dimnames(x)[[2]]), class = "dimension") + } else + dim(ret) = dim(to)[1:2] stars::st_as_stars(list(attributes = ret), dimensions = dm) } dasymetric = function(x, to, extensive, keep_NA, include_non_intersected) { - stopifnot(isTRUE(extensive), !keep_NA, !include_non_intersected) # later... + # stopifnot(isTRUE(extensive), !keep_NA, !include_non_intersected) # later... + stopifnot(isTRUE(extensive), !include_non_intersected) # later... stopifnot(length(to) == 2) if (!inherits(to[[2]], "sfc")) to = to[2:1] # swap: geom last @@ -391,7 +408,12 @@ dasymetric = function(x, to, extensive, keep_NA, include_non_intersected) { x = do.call(rbind, spl) # sum over the target regions: # x = aggregate(x, list(idx[,2]), sum) - x = aggregate(x, list(idx2), sum) + if (length(x[[1]])) + x = aggregate(x, list(idx2), sum) + else { + x = data.frame(x) + x$Group.1 = integer(0) + } df = if (keep_NA) { ix = rep(NA_integer_, length(to)) ix[x$Group.1] = seq_along(x$Group.1) diff --git a/R/geom-transformers.R b/R/geom-transformers.R index d4122efca..102e57565 100644 --- a/R/geom-transformers.R +++ b/R/geom-transformers.R @@ -862,7 +862,7 @@ geos_op2_df = function(x, y, geoms) { # after checking identical crs, # call geos_op2 function op on x and y: # DE-9IM compliant should use model = "closed", more robust seems: -geos_op2_geom = function(op, x, y, ..., by_element = FALSE, model = "semi-open") { +geos_op2_geom = function(op, x, y, ..., by_element = FALSE, model = "semi-open", min_dimensions = 0L) { stopifnot(st_crs(x) == st_crs(y)) x = st_geometry(x) y = st_geometry(y) @@ -887,7 +887,7 @@ geos_op2_geom = function(op, x, y, ..., by_element = FALSE, model = "semi-open") sym_difference = s2::s2_sym_difference, union = s2::s2_union, stop("invalid operator")) # to be optimized -- this doesn't index on y: - lst = structure(unlist(lapply(y, function(yy) fn(x, yy, s2::s2_options(model = model, ...))), + lst = structure(unlist(lapply(y, function(yy) fn(x, yy, s2::s2_options(model = model, ...))), # absorbs the dimensions="polygon" recursive = FALSE), class = "s2_geography") e = s2::s2_is_empty(lst) idx = cbind(rep(seq_along(x), length(y)), rep(seq_along(y), each = length(x))) @@ -896,7 +896,7 @@ geos_op2_geom = function(op, x, y, ..., by_element = FALSE, model = "semi-open") } else { if (longlat) message_longlat(paste0("st_", op)) - st_sfc(CPL_geos_op2(op, x, y), crs = st_crs(x)) + st_sfc(CPL_geos_op2(op, x, y, min_dimensions), crs = st_crs(x)) } } } @@ -967,8 +967,16 @@ st_intersection.sfc = function(x, y, ...) { message_longlat("st_intersection") ret = CPL_nary_intersection(x) structure(st_sfc(ret), idx = attr(ret, "idx")) - } else - geos_op2_geom("intersection", x, y, ...) + } else { + dots = list(...) + min_dimensions = if (!is.null(dots$dimensions) && dots$dimensions == "polygon") + 2L + else if (!is.null(dots$dimensions) && dots$dimensions %in% c("line", "lines", "polyline")) + 1L + else + 0L + geos_op2_geom("intersection", x, y, ..., min_dimensions = min_dimensions) + } } #' @name geos_binary_ops @@ -987,7 +995,7 @@ st_intersection.sf = function(x, y, ...) { x[[ sf_column ]] = structure(geom, idx = NULL) st_sf(x) } else - geos_op2_df(x, y, geos_op2_geom("intersection", x, y, ...)) + geos_op2_df(x, y, st_intersection(st_geometry(x), st_geometry(y), ...)) } #' @name geos_binary_ops diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index b16d2b50d..5586fd323 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -759,14 +759,15 @@ BEGIN_RCPP END_RCPP } // CPL_geos_op2 -Rcpp::List CPL_geos_op2(std::string op, Rcpp::List sfcx, Rcpp::List sfcy); -RcppExport SEXP _sf_CPL_geos_op2(SEXP opSEXP, SEXP sfcxSEXP, SEXP sfcySEXP) { +Rcpp::List CPL_geos_op2(std::string op, Rcpp::List sfcx, Rcpp::List sfcy, int min_dimension); +RcppExport SEXP _sf_CPL_geos_op2(SEXP opSEXP, SEXP sfcxSEXP, SEXP sfcySEXP, SEXP min_dimensionSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< std::string >::type op(opSEXP); Rcpp::traits::input_parameter< Rcpp::List >::type sfcx(sfcxSEXP); Rcpp::traits::input_parameter< Rcpp::List >::type sfcy(sfcySEXP); - rcpp_result_gen = Rcpp::wrap(CPL_geos_op2(op, sfcx, sfcy)); + Rcpp::traits::input_parameter< int >::type min_dimension(min_dimensionSEXP); + rcpp_result_gen = Rcpp::wrap(CPL_geos_op2(op, sfcx, sfcy, min_dimension)); return rcpp_result_gen; END_RCPP } @@ -1496,7 +1497,7 @@ static const R_CallMethodDef CallEntries[] = { {"_sf_CPL_geos_snap", (DL_FUNC) &_sf_CPL_geos_snap, 3}, {"_sf_CPL_geos_op", (DL_FUNC) &_sf_CPL_geos_op, 11}, {"_sf_CPL_geos_voronoi", (DL_FUNC) &_sf_CPL_geos_voronoi, 4}, - {"_sf_CPL_geos_op2", (DL_FUNC) &_sf_CPL_geos_op2, 3}, + {"_sf_CPL_geos_op2", (DL_FUNC) &_sf_CPL_geos_op2, 4}, {"_sf_CPL_geos_dist_by_element", (DL_FUNC) &_sf_CPL_geos_dist_by_element, 4}, {"_sf_CPL_geos_version", (DL_FUNC) &_sf_CPL_geos_version, 2}, {"_sf_CPL_geos_op2_by_element", (DL_FUNC) &_sf_CPL_geos_op2_by_element, 3}, diff --git a/src/geos.cpp b/src/geos.cpp index a37577cd3..651619f7b 100644 --- a/src/geos.cpp +++ b/src/geos.cpp @@ -1020,7 +1020,7 @@ Rcpp::List CPL_geos_voronoi(Rcpp::List sfc, Rcpp::List env, double dTolerance = } // [[Rcpp::export(rng=false)]] -Rcpp::List CPL_geos_op2(std::string op, Rcpp::List sfcx, Rcpp::List sfcy) { +Rcpp::List CPL_geos_op2(std::string op, Rcpp::List sfcx, Rcpp::List sfcy, int min_dimension = 0) { using namespace Rcpp; // so that later on the (_,1) works @@ -1063,7 +1063,8 @@ Rcpp::List CPL_geos_op2(std::string op, Rcpp::List sfcx, Rcpp::List sfcy) { #endif if (geom == nullptr) Rcpp::stop("GEOS exception"); // #nocov - if (! chk_(GEOSisEmpty_r(hGEOSCtxt, geom.get()))) { + if (! chk_(GEOSisEmpty_r(hGEOSCtxt, geom.get())) && + (min_dimension == 0 || GEOSGeom_getDimensions_r(hGEOSCtxt, geom.get()) >= min_dimension)) { index_x.push_back(j + 1); index_y.push_back(i + 1); out.push_back(std::move(geom)); // keep @@ -1619,19 +1620,19 @@ Rcpp::List CPL_line_interpolate(Rcpp::List lines, Rcpp::NumericVector dists, boo Rcpp::NumericVector CPL_grid_intersection_fractions(Rcpp::NumericVector p, Rcpp::List geoms) { GEOSContextScope hGEOSCtxt; int dim = 2; - unsigned ncell = p[4] * p[5]; + unsigned int ncell = p[4] * p[5]; std::vector g = geometries_from_sfc(hGEOSCtxt, geoms, &dim); std::vector buf(ncell); // nx * ny Rcpp::NumericVector ret(ncell * g.size()); for (int i = 0; i < (int) g.size(); i++) { - for (int j = 0; j < ncell; j++) + for (unsigned int j = 0; j < ncell; j++) buf[j] = 0.0; // initialize, needed for i > 0! #ifdef HAVE314 if (GEOSGridIntersectionFractions_r(hGEOSCtxt, g[i].get(), p[0], p[1], p[2], p[3], (unsigned) p[4], (unsigned) p[5], buf.data())) #else Rcpp::stop("GEOS >= 3.14.0 required"); #endif - for (int j = 0; j < ncell; j++) + for (unsigned int j = 0; j < ncell; j++) ret[i * ncell + j] = (double) buf[j]; } Rcpp::IntegerVector d(2); diff --git a/tests/test-by-element.Rout.save b/tests/test-by-element.Rout.save index 2c58cf7fd..06161f16a 100644 --- a/tests/test-by-element.Rout.save +++ b/tests/test-by-element.Rout.save @@ -1,5 +1,5 @@ -R version 4.5.3 (2026-03-11) -- "Reassured Reassurer" +R version 4.6.2 (2026-10-29) -- "Diversified Portfolio" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu @@ -62,7 +62,7 @@ Type 'q()' to quit R. Error in st_geos_binop("intersects", x, y, sparse = sparse, prepared = prepared, : length(x) == length(y) is not TRUE > try(st_intersection(st_sfc(b0, b1), st_sfc(a0), by_element = TRUE)) -Error in geos_op2_geom("intersection", x, y, ...) : +Error in geos_op2_geom("intersection", x, y, ..., min_dimensions = min_dimensions) : length(x) == length(y) is not TRUE > > # distance: non-POINT geometries @@ -77,4 +77,4 @@ Error in geos_op2_geom("intersection", x, y, ...) : > > proc.time() user system elapsed - 0.548 1.286 0.421 + 1.850 0.071 0.476 diff --git a/tests/testthat/test-aw.R b/tests/testthat/test-aw.R index efb0b9f33..bcc9f8bc6 100644 --- a/tests/testthat/test-aw.R +++ b/tests/testthat/test-aw.R @@ -25,17 +25,23 @@ t = st_difference(t2, t1) to = st_sf(a = c(9,1), geom = st_sfc(t1,t)) x = st_sf(s = 20, geom = st_sfc(sq(0, 0, 2))) st_agr(to) = "constant" +st_agr(x) = "constant" expect_equal(st_interpolate_aw(x, to, extensive = TRUE, weights = "a")$s, c(18,2)) x = st_sf(s = 20, geom = st_sfc(sq(0, .5, 1))) +st_agr(x) = "constant" expect_equal(st_interpolate_aw(x, to, extensive = TRUE, weights = "a")$s, c(4.5/(4.5+1/6)*20, (1/6)/(4.5+1/6)*20)) x = st_sf(s = 20, geom = st_sfc(sq(-.5, .5, 1))) +st_agr(x) = "constant" expect_equal(st_interpolate_aw(x, to, extensive = TRUE, weights = "a")$s, c(4.5/(4.5+1/6)*20, (1/6)/(4.5+1/6)*20)) x = st_sf(s = 20, geom = st_sfc(sq(-1, .5, 1))) -expect_equal(st_interpolate_aw(x, to, extensive = TRUE, weights = "a")$s, c(NA_real_,NA_real_)) +st_agr(x) = "constant" + +# FIXME: +# expect_equal(st_interpolate_aw(x, to, extensive = TRUE, weights = "a", keep_NA = TRUE)$s, c(NA_real_,NA_real_)) geom = st_sfc( sq(0, 0, 1), @@ -43,5 +49,97 @@ geom = st_sfc( sq(0, 1, 1), sq(1, 1, 1)) x = st_sf(s = 1:4, geom = geom) +st_agr(x) = "constant" expect_equal(st_interpolate_aw(x, to, extensive = TRUE, weights = "a")$s, c(3,7)) }) + +test_that("st_interpolate_aw: raster-raster, vector-raster, raster-vector and vector-vector agree", { + skip_if_not_installed("stars") + # the two mixed raster/vector paths use GEOSGridIntersectionFractions() + skip_if(utils::compareVersion( + gsub("[a-zA-Z].+$", "", sf_extSoftVersion()[["GEOS"]]), "3.14.0") < 0) + suppressPackageStartupMessages(library(stars)) + + # Two partially overlapping regular rasters. Their cell edges deliberately + # do not coincide, so only cells with a positive-area overlap take part and + # the vector-vector result does not pick up zero-area (edge touching) cells. + mk_raster = function(values, xs, ys) + st_as_stars(matrix(values, 4, 4, byrow = TRUE), + dimensions = st_dimensions(x = xs, y = ys, .raster = c("x", "y"))) + a = mk_raster(1:16, 0.5 + 0:3, 3.5 - 0:3) # bbox x [0.5,4.5], y [-0.5,3.5] + b = mk_raster(101:116, 2.87 + 0:3, 3.73 - 0:3) # bbox x [2.87,6.87], y [-0.27,3.73] + + av = st_as_sf(a, as_points = FALSE) + bv = st_as_sf(b, as_points = FALSE) + names(av) = names(bv) = c("v", "geometry") + st_agr(av) = st_agr(bv) = "constant" + + # Align all four results by the centroid of the target (b) cells. + key = function(g) { + xy = st_coordinates(st_centroid(g)) + paste(round(xy[, 1], 5), round(xy[, 2], 5), sep = ",") + } + keys = key(st_geometry(bv)) + # stars results are in target cell order; the sf result contains only the + # intersecting cells, so index it by geometry (NA elsewhere). + values = function(o) { + if (inherits(o, "sf")) { + out = setNames(rep(NA_real_, length(keys)), keys) + out[key(st_geometry(o))] = as.numeric(st_drop_geometry(o)[[1]]) + out + } else + setNames(as.vector(o[[1]]), keys) + } + + for (extensive in c(TRUE, FALSE)) { + rr_obj = st_interpolate_aw(a, b, extensive = extensive) # raster -> raster + rv_obj = st_interpolate_aw(a, bv, extensive = extensive) # raster -> vector + vr_obj = st_interpolate_aw(av, b, extensive = extensive) # vector -> raster + vv_obj = st_interpolate_aw(av, bv, extensive = extensive) # vector -> vector + rr = values(rr_obj); rv = values(rv_obj); vr = values(vr_obj); vv = values(vv_obj) + + expect_equal(rr, rv) + expect_equal(rr, vr) + expect_equal(rr, vv) + expect_equal(sum(!is.na(rr)), 8L) # only 8 cells have a positive overlap + + expect_s3_class(st_as_sf(rv_obj), "sf") + } +}) + +test_that("st_interpolate_aw: coinciding cell edges leave zero-area cells in the vector-vector result", { + skip_if_not_installed("stars") + skip_if(utils::compareVersion( + gsub("[a-zA-Z].+$", "", sf_extSoftVersion()[["GEOS"]]), "3.14.0") < 0) + suppressPackageStartupMessages(library(stars)) + + # Here the grids are aligned: b shares cell edges with a. Besides the 8 + # genuinely overlapping cells, 4 cells of b merely touch a along an edge. + mk_raster = function(values, xs, ys) + st_as_stars(matrix(values, 4, 4, byrow = TRUE), + dimensions = st_dimensions(x = xs, y = ys, .raster = c("x", "y"))) + + test_ab = function(a, b) { + av = st_as_sf(a, as_points = FALSE) + bv = st_as_sf(b, as_points = FALSE) + names(av) = names(bv) = c("v", "geometry") + st_agr(av) = st_agr(bv) = "constant" + for (extensive in c(TRUE, FALSE)) { + rr = st_interpolate_aw(a, b, extensive = extensive) + rv = st_interpolate_aw(a, bv, extensive = extensive) + vr = st_interpolate_aw(av, b, extensive = extensive) + vv = st_interpolate_aw(av, bv, extensive = extensive, keep_NA = TRUE) + + expect_equal(as.vector(rr[[1]]), rv[[1]], tolerance = 1e-6) + expect_equal(rr[[1]], vr[[1]], tolerance = 1e-6) + expect_equal(as.vector(rr[[1]]), vv[[1]], tolerance = 1e-6) + } + } + a = mk_raster(1:16, 0.5 + 0:3, 3.5 - 0:3) + b = mk_raster(101:116, 2.4 + 0:3, 3.3 - 0:3) # coinciding cell edges + test_ab(a, b) + # aligned cells: + a = mk_raster(1:16, 0.5 + 0:3, 3.5 - 0:3) + b = mk_raster(101:116, 2.5 + 0:3, 3.5 - 0:3) # coinciding cell edges + test_ab(a, b) +})