From 93a25fd8e2f5c6af7c080f92141cb2b765a04a84 Mon Sep 17 00:00:00 2001 From: Roger Bivand Date: Wed, 11 Sep 2024 10:16:10 +0200 Subject: [PATCH] address #2436 --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/transform.R | 5 ++++- src/gdal.cpp | 18 +++++++++++------- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ff4743808..433ecd9cf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: sf -Version: 1.0-17 +Version: 1.0-18 Title: Simple Features for R Authors@R: c(person(given = "Edzer", diff --git a/NEWS.md b/NEWS.md index e4ddcdf7a..12add0430 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# version 1.0-18 + +* fix build failure with GDAL < 3.4.0 #2436 + # version 1.0-17 * add `st_transform()` method for `bbox` objects; this uses OGRCoordinateTransformation::TransformBounds(), densifying first and antemeridian proof; #2415 diff --git a/R/transform.R b/R/transform.R index 96103d7b8..b3ed50a1e 100644 --- a/R/transform.R +++ b/R/transform.R @@ -170,7 +170,10 @@ st_transform.sfg = function(x, crs = st_crs(x), ...) { #' @param densify integer, number of points for discretizing lines between bounding box corner points; see Details #' @details the method for `bbox` objects densifies lines for geographic coordinates along Cartesian lines, not great circle arcs st_transform.bbox = function(x, crs, ..., densify = 21) { - st_bbox(CPL_transform_bounds(x, st_crs(crs), densify), crs = crs) + if (sf_extSoftVersion()["GDAL"] >= "3.4.0") + st_bbox(CPL_transform_bounds(x, st_crs(crs), densify), crs = crs) + else + stop("method not available for GDAL: ", sf_extSoftVersion()["GDAL"]) } #' @name st_transform diff --git a/src/gdal.cpp b/src/gdal.cpp index 2246c6d2f..0410ba594 100644 --- a/src/gdal.cpp +++ b/src/gdal.cpp @@ -673,6 +673,17 @@ Rcpp::List CPL_transform(Rcpp::List sfc, Rcpp::List crs, Rcpp::NumericVector CPL_transform_bounds(Rcpp::NumericVector bb, Rcpp::List crs_dst, int densify_pts = 21) { + Rcpp::NumericVector ret(4); + ret[0] = 0.0; + ret[1] = 0.0; + ret[2] = 0.0; + ret[3] = 0.0; + Rcpp::CharacterVector names(4); + names(0) = "xmin"; + names(1) = "ymin"; + names(2) = "xmax"; + names(3) = "ymax"; + ret.attr("names") = names; #if GDAL_VERSION_NUM >= 3040000 if (bb.size() != 4) Rcpp::stop("bb should have length 4"); @@ -693,17 +704,10 @@ Rcpp::NumericVector CPL_transform_bounds(Rcpp::NumericVector bb, Rcpp::List crs_ int success = ct->TransformBounds(bb[0], bb[1], bb[2], bb[3], &xmin, &ymin, &xmax, &ymax, densify_pts); if (!success) Rcpp::stop("transform_bounds(): failures encountered"); // #nocov - Rcpp::NumericVector ret(4); ret[0] = xmin; ret[1] = ymin; ret[2] = xmax; ret[3] = ymax; - Rcpp::CharacterVector names(4); - names(0) = "xmin"; - names(1) = "ymin"; - names(2) = "xmax"; - names(3) = "ymax"; - ret.attr("names") = names; ct->DestroyCT(ct); dst->Release(); src->Release();