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 rcmdcheck warnings #874

Merged
merged 3 commits into from
Aug 14, 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
3 changes: 2 additions & 1 deletion R/layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ addRasterLegend <- function(map, x, layer = 1, ...) {
#
# remove the levels to get the raw cell values
levels(x) <- NULL
color_info <- base::subset(color_info, value %in% terra::unique(x)[[1]])
value_in_layer <- color_info$value %in% terra::unique(x)[[1]]
color_info <- color_info[value_in_layer & !is.na(value_in_layer), ]

res <- if (is.data.frame(lvls)) {
# Use the labels from levels(x), and look up the matching colors.
Expand Down
23 changes: 14 additions & 9 deletions R/normalize-terra.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,24 @@ polygonData.SpatVector <- function(obj) {

# helpers -----------------------------------------------------------------
assure_crs_terra <- function(x) {
prj <- crs(x, proj=TRUE)
if (is.lonlat(x, perhaps=TRUE, warn=FALSE)) {
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 <- project(x, "+proj=longlat +datum=WGS84")
x <- terra::project(x, "+proj=longlat +datum=WGS84")
}
return(x)
}
# Don't have enough information to check
if (is.na(crs) || (crs=="")) {
warning("SpatVector layer is not long-lat data", call. = FALSE)
return(x)
}
project(x, "+proj=longlat +datum=WGS84")

terra::project(x, "+proj=longlat +datum=WGS84")
}

check_crs_terra <- function(x) {
Expand Down