Skip to content

Commit 5bfc25a

Browse files
committed
fixes
1 parent efe1ead commit 5bfc25a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

R/layers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ addRasterImage_SpatRaster <- function(
454454
) {
455455

456456
# terra 1.5-50 has terra::has.RGB()
457-
if (x@ptr$rgb) {
457+
if (has.RGB(x)) {
458458
# RGB(A) channels to color table
459459
x <- terra::colorize(x, "col")
460460
} else if (terra::nlyr(x) > 1) {

R/normalize-terra.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ polygonData.SpatVector <- function(obj) {
5050

5151

5252
# helpers -----------------------------------------------------------------
53+
assure_crs_terra <- function(x) {
54+
prj <- crs(x, proj=TRUE)
55+
if (is.lonlat(x, perhaps=TRUE, warn=FALSE)) {
56+
if (!grepl("+datum=WGS84", prj, fixed = TRUE)) {
57+
x <- project(x, "+proj=longlat +datum=WGS84")
58+
}
59+
return(x)
60+
}
61+
# Don't have enough information to check
62+
if (is.na(crs) || (crs=="")) {
63+
warning("SpatVector layer is not long-lat data", call. = FALSE)
64+
return(x)
65+
}
66+
project(x, "+proj=longlat +datum=WGS84")
67+
}
5368

5469
check_crs_terra <- function(x) {
5570
crs <- crs(x)

0 commit comments

Comments
 (0)