Skip to content

Commit

Permalink
check ok, fixed #1001
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Dec 25, 2024
1 parent 39766de commit 0af73cd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
8 changes: 4 additions & 4 deletions R/spatial_non_supported.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#' @export
tmapGetShapeMeta1.default = function(shp, o) {
stop("Specified shp argument of tm_shape is a ", class(shp)[1], ", which is a recognized/supported spatial data class.", call. = FALSE)
stop("Specified shp argument of tm_shape is a ", class(shp)[1], ", which is not a recognized/supported spatial data class.", call. = FALSE)
}

#' @export
tmapGetShapeMeta2.default = function(shp, smeta, o) {
stop("Specified shp argument of tm_shape is a ", class(shp)[1], ", which is a recognized/supported spatial data class.", call. = FALSE)
stop("Specified shp argument of tm_shape is a ", class(shp)[1], ", which is not a recognized/supported spatial data class.", call. = FALSE)
}

#' @export
tmapSubsetShp.default = function(shp, vars) {
stop("Specified shp argument of tm_shape is a ", class(shp)[1], ", which is a recognized/supported spatial data class.", call. = FALSE)
stop("Specified shp argument of tm_shape is a ", class(shp)[1], ", which is not a recognized/supported spatial data class.", call. = FALSE)
}

#' @export
tmapShape.default = function(shp, is.main, crs, bbox, unit, filter, shp_name, smeta, o, tmf) {
stop("Specified shp argument of tm_shape is a ", class(shp)[1], ", which is a recognized/supported spatial data class.", call. = FALSE)
stop("Specified shp argument of tm_shape is a ", class(shp)[1], ", which is not a recognized/supported spatial data class.", call. = FALSE)
}
2 changes: 1 addition & 1 deletion R/tm_layers_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' @example ./examples/tm_raster.R
#' @export
tm_raster = function(col = tm_vars(),
col.scale = tm_scale(value.na = "#00000000"),
col.scale = tm_scale(),
col.legend = tm_legend(),
col.chart = tm_chart_none(),
col.free = NA,
Expand Down
3 changes: 2 additions & 1 deletion R/tmapScale_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ get_scale_defaults = function(scale, o, aes, layer, cls, ct = NULL) {
m = getPalMeta(as.character(values[1]))
ona = getAesOption("value.na", o, aes, layer, cls = cls)

if ((!is.na(ona) && "value.na" %in% scale$called) || is.null(m)) {
# take option value.na instead of cols4all palette na-color in these three cases:
if ((!is.na(ona) && "value.na" %in% scale$called) || is.null(m) || substr(ona, 8, 9) == "00") {
ona
} else{
getPalNA(as.character(values[1]))
Expand Down
40 changes: 20 additions & 20 deletions tests/testthat/test-terra-stars.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

test_that("terra works", {

skip_on_cran()
skip_if_not_installed("spDataLarge")
landsat = terra::rast(system.file("raster/landsat.tif", package = "spDataLarge"))
Expand All @@ -9,44 +9,44 @@ test_that("terra works", {
land_terra = terra::rast(tmap::land)
names(land_terra) <- names(tmap::land)
tm_shape(land_terra) + tm_raster("trees")

expect_snapshot(error = TRUE, {
tm_shape(land_terra) + tm_raster("treess")
})

# FIXME this is not expected.

tm_shape(landsat) +
tm_rgb(tm_vars(c("landsat_4", "landsat_3", "landsat_2"), multivariate = TRUE), col.scale = tm_scale_rgb(maxColorValue = 31961))
tm_rgb(tm_vars(c("landsat_4", "landsat_3", "landsat_2"), multivariate = TRUE), col.scale = tm_scale_rgb(max_color_value = 31961))
# Defaults of stars and terra are identical.
tm_shape(landsat) + tm_raster(col.free = FALSE)
tm_shape(landsat) +
tm_raster(c("landsat_1", "landsat_2", "landsat_3", "landsat_4"), col.free = FALSE) +
tm_raster(c("landsat_1", "landsat_2", "landsat_3", "landsat_4"), col.free = FALSE) +
tm_options(max.raster = 10000)

skip_on_os("linux")
tm_shape(landsat) + tm_raster("landsat_1", col.free = FALSE)

})

test_that("stars works", {

skip_on_cran()
skip_if_not_installed("spDataLarge")
landsat = stars::read_stars(system.file("raster/landsat.tif", package = "spDataLarge"))
land_stars = tmap::land

tm_shape(land_stars) + tm_raster("trees")

tm_shape(land_stars) + tm_raster("treess")

# Fixed (issue #789)
# Removed the argument raster.warp from v4, because it is not useful.
# Removed the argument raster.warp from v4, because it is not useful.
# Now the first strategy is warp (st_warp) and if unsuccessful,
# then throw a warning and try a (slow) transformation (st_transform).
# Somehow, the warp won't work with "robin". However, with crs = "+proj=eck4" is does work.
expect_no_warning(tm_shape(landsat) + tm_raster("landsat.tif", col.free = FALSE))

p <- tm_shape(landsat) + tm_raster(col.free = FALSE)
tm_shape(landsat) +
tm_raster("landsat.tif") +
Expand All @@ -66,10 +66,10 @@ test_that("multi rast works.", {
tm_shape(multi_rast[[3:1]]) +
tm_rgb()
})

tm_shape(multi_rast) +
tm_rgb(tm_vars(c("landsat_4", "landsat_3", "landsat_2"), multivariate = TRUE), col.scale = tm_scale_rgb(maxColorValue = 31961))
tm_rgb(tm_vars(c("landsat_4", "landsat_3", "landsat_2"), multivariate = TRUE), col.scale = tm_scale_rgb(max_color_value = 31961))

})

test_that("Both approaches work for stars.", {
Expand All @@ -79,11 +79,11 @@ test_that("Both approaches work for stars.", {
# direct approach
landsat_stars = stars::read_stars(system.file("raster/landsat.tif", package = "spDataLarge"))
expect_no_condition(tm_shape(landsat_stars) +
tm_rgb(tm_vars("band", dimvalues = c(4,3,2)), col.scale = tm_scale_rgb(maxColorValue = 31961))
tm_rgb(tm_vars("band", dimvalues = c(4,3,2)), col.scale = tm_scale_rgb(max_color_value = 31961))
)

# indirect approach
landsat_stars2 = split(landsat_stars, "band")
tm_shape(landsat_stars2) +
tm_rgb(tm_vars(c("X4", "X3", "X2"), multivariate = TRUE), col.scale = tm_scale_rgb(maxColorValue = 31961))
tm_rgb(tm_vars(c("X4", "X3", "X2"), multivariate = TRUE), col.scale = tm_scale_rgb(max_color_value = 31961))
})

0 comments on commit 0af73cd

Please sign in to comment.