From 57cf3aea980a0f4f837b94925301b0fa7aa0b433 Mon Sep 17 00:00:00 2001 From: mtennekes Date: Sat, 23 Sep 2023 20:56:21 +0200 Subject: [PATCH] fixed #789 --- R/misc_stars.R | 19 ++++++++----------- R/step1_rearrange.R | 2 +- R/step3_trans.R | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/R/misc_stars.R b/R/misc_stars.R index 4b8457bb..24d8cc3d 100644 --- a/R/misc_stars.R +++ b/R/misc_stars.R @@ -127,20 +127,17 @@ get_xy_dim = function(x) { transwarp = function(x, crs, raster.warp) { # NOTE: dropped colors after st_warp fixed in stars 0.4-2 shpcolors = attr(x[[1]], "colors") - if (raster.warp) { - y = tryCatch({ - stars::st_warp(x, crs = crs) - }, error = function(e) { - # tm_shape does not have a raster.warp argument. - stop("Unable to warp stars. You could try with raster.warp = FALSE (argument of tm_shape)", call. = FALSE) - }) - } else { - y = tryCatch({ + + y = tryCatch({ + stars::st_warp(x, crs = crs) + }, error = function(e) { + warning("Unable to warp stars. Stars will be transformed now (which will take some time).", call. = FALSE) + tryCatch({ sf::st_transform(x, crs = crs) }, error = function(e) { - stop("Unable to transform stars", call. = FALSE) + stop("Also unable to transform stars", call. = FALSE) }) - } + }) if (!is.null(shpcolors)) attr(y[[1]], "colors") = shpcolors y } diff --git a/R/step1_rearrange.R b/R/step1_rearrange.R index 57cac860..628ff920 100644 --- a/R/step1_rearrange.R +++ b/R/step1_rearrange.R @@ -127,7 +127,7 @@ step1_rearrange = function(tmel) { } # crs in options refers to which crs is used in the plot, not necessarily in the transformation (step 3) - crs_option = o$crs + crs_option = sf::st_crs(o$crs) # get main crs (used in step 3, not necessarily in the plot (e.g. view mode will use 4326/3857)) crs_main = if (any_data_layer) get_crs(tms) else NA diff --git a/R/step3_trans.R b/R/step3_trans.R index 24bab0f5..4f9338f5 100644 --- a/R/step3_trans.R +++ b/R/step3_trans.R @@ -32,7 +32,7 @@ step3_trans = function(tm) { crs_reproject_shpTM = function(s, crs) { # crs can be a list per class (due to leaflet EPSG:3857 requirement for raster images) - crs2 = get_option_class(crs, class = class(s$shp)) + crs2 = sf::st_crs(get_option_class(crs, class = class(s$shp))) if (sf::st_crs(s$shp) != crs2) { s = do.call(tmapReproject, c(s, list(crs = crs2))) }