From e15a997421832f6fc98681390f739b99f9237b06 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Mon, 27 Nov 2023 17:12:15 -0500 Subject: [PATCH] fix(check_crs_terra): Prefix `terra:crs()` call (#894) --- NEWS.md | 2 ++ R/normalize-terra.R | 25 +++---------------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7ad5b893b..dc1d14a45 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # leaflet (development version) +* Fixed #893: Correctly call `terra::crs()` when checking the CRS of a `SpatVector` object in `pointData()` or `polygonData()` (thanks @mkoohafkan, #894). + # leaflet 2.2.1 * When `addProviderTiles()` is used with `{leaflet.providers}` version 2.0.0 or later, the `leaflet-providers` HTML dependency produced can be correctly cached by knitr. When used with older versions of `{leaflet.providers}`, the HTML dependency uses temp files that break knitr's caching mechanism (thanks @qdread, @jaredlander; #884). diff --git a/R/normalize-terra.R b/R/normalize-terra.R index e2f1c0eb6..9e15048fe 100644 --- a/R/normalize-terra.R +++ b/R/normalize-terra.R @@ -50,29 +50,10 @@ polygonData.SpatVector <- function(obj) { # helpers ----------------------------------------------------------------- -assure_crs_terra <- function(x) { +check_crs_terra <- function(x) { stopifnot(is_installed("terra")) - prj <- raster::crs(x, proj = TRUE) - - if (is.na(prj) || (prj == "")) { - # Don't have enough information to check - warning("SpatVector layer is not long-lat data", call. = FALSE) - return(x) - } - - if (terra::is.lonlat(x, perhaps = TRUE, warn = FALSE)) { - if (!grepl("+datum=WGS84", prj, fixed = TRUE)) { - x <- terra::project(x, "+proj=longlat +datum=WGS84") - } - return(x) - } - - terra::project(x, "+proj=longlat +datum=WGS84") -} - -check_crs_terra <- function(x) { - crs <- crs(x) + crs <- terra::crs(x) # Don't have enough information to check if (is.na(crs) || (crs=="")) @@ -82,7 +63,7 @@ check_crs_terra <- function(x) { warning("SpatVector layer is not long-lat data", call. = FALSE) } - prj <- crs(x, proj=TRUE) + prj <- terra::crs(x, proj=TRUE) if (!grepl("+datum=WGS84", prj, fixed = TRUE)) { warning( "SpatVector layer has inconsistent datum (", prj, ").\n",