@@ -325,11 +325,11 @@ addRasterImage <- function(
325
325
addRasterLegend <- function (map , x , layer = 1 , ... ) {
326
326
stopifnot(inherits(x , " SpatRaster" ))
327
327
stopifnot(length(layer ) == 1 && layer > 0 && layer < = terra :: nlyr(x ))
328
-
329
- # # might as well do this here and only once. Subsetting would otherwise have been necessary in
328
+
329
+ # # might as well do this here and only once. Subsetting would otherwise have been necessary in
330
330
# # color_info <- base::subset(color_info, value %in% terra::values(x))
331
331
x <- x [[layer ]]
332
-
332
+
333
333
# Retrieve the color table from the layer. If one doesn't exist, that means
334
334
# the raster was colored some other way, like using colorFactor or something,
335
335
# and the regular addLegend() is designed for those cases.
@@ -348,13 +348,13 @@ addRasterLegend <- function(map, x, layer = 1, ...) {
348
348
lvls <- terra :: levels(x )[[1 ]]
349
349
350
350
# Drop values that aren't part of the layer
351
- # # unlike "values", "unique" is memory-safe; it does not load all values
351
+ # # unlike "values", "unique" is memory-safe; it does not load all values
352
352
# # into memory if the raster is large. So instead of:
353
353
354
354
# color_info <- base::subset(color_info, value %in% terra::values(x))
355
355
356
356
# # remove the levels to get the raw cell values
357
- levels(x ) <- NULL
357
+ levels(x ) <- NULL
358
358
color_info <- base :: subset(color_info , value %in% terra :: unique(x )[[1 ]])
359
359
360
360
res <- if (is.data.frame(lvls )) {
@@ -463,9 +463,14 @@ addRasterImage_SpatRaster <- function(
463
463
maxBytes = 4 * 1024 * 1024 ,
464
464
data = getMapData(map )
465
465
) {
466
+ if (! is_installed(" terra" , " 1.6-3" )) { # for terra::has.RGB()
467
+ stop(
468
+ " `addRasterImage()` for SpatRaster objects requires {terra} 1.6-3 or higher" ,
469
+ call. = FALSE
470
+ )
471
+ }
466
472
467
- # terra 1.5-50 has terra::has.RGB()
468
- if (has.RGB(x )) {
473
+ if (terra :: has.RGB(x )) {
469
474
# RGB(A) channels to color table
470
475
x <- terra :: colorize(x , " col" )
471
476
} else if (terra :: nlyr(x ) > 1 ) {
0 commit comments