Skip to content

Commit

Permalink
fixed #789
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Sep 23, 2023
1 parent 856a822 commit 57cf3ae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
19 changes: 8 additions & 11 deletions R/misc_stars.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion R/step1_rearrange.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/step3_trans.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down

0 comments on commit 57cf3ae

Please sign in to comment.