Skip to content

Commit

Permalink
fix(check_crs_terra): Prefix terra:crs() call (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie authored Nov 27, 2023
1 parent d8c9794 commit e15a997
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
25 changes: 3 additions & 22 deletions R/normalize-terra.R
Original file line number Diff line number Diff line change
Expand Up @@ -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==""))
Expand All @@ -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",
Expand Down

0 comments on commit e15a997

Please sign in to comment.