Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(check_crs_terra): Prefix terra:crs() call #894

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
prj <- terra::crs(x, proj=TRUE)
if (!grepl("+datum=WGS84", prj, fixed = TRUE)) {
warning(
"SpatVector layer has inconsistent datum (", prj, ").\n",
Expand Down
Loading