You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently looking for help with the following problem:
When overlaying (add_overlay) a digital elevation model for Switzerland with some colors from a raster, the result somehow shows different colors and I cannot find the issue. Below you can see the (very simple) code example, the expected colors and the rayshader coloring. Since I already invested a considerable amount of time into it and can't find it, I hoped that someone knows whether my code is wrong - which most probably is the reason - or if there is some coloring issue in the add_overlay function.
Thanks in advance for your help, highly appreciated.
Hi
I am currently looking for help with the following problem:
When overlaying (add_overlay) a digital elevation model for Switzerland with some colors from a raster, the result somehow shows different colors and I cannot find the issue. Below you can see the (very simple) code example, the expected colors and the rayshader coloring. Since I already invested a considerable amount of time into it and can't find it, I hoped that someone knows whether my code is wrong - which most probably is the reason - or if there is some coloring issue in the add_overlay function.
Thanks in advance for your help, highly appreciated.
Benjamin
packages:
library(terra)
library(dplyr)
library(rayshader)
get layers
setwd("...")
elevation <- rast("DHM200.asc")
crs(elevation) <- crs('+init=epsg:21781')
winner_losers_overlay <- rast("Winners_and_Losers_20241209.tif")
elevation <- terra::project(elevation, winner_losers_overlay)
prepare overlay
winner_losers_overlay[winner_losers_overlay>0] <- 3
winner_losers_overlay[winner_losers_overlay<0] <- 2
winner_losers_overlay[winner_losers_overlay==0] <- 1
coltb <- data.frame(value=c(1,2,3), col=c("#F2F2F2","#EE2C2C","#43CD80"))
has.colors(winner_losers_overlay)
coltab(winner_losers_overlay) <- coltb
create overlay with rgb colors
from <- 1:3
to <- t(col2rgb(c("#F2F2F2","#EE2C2C","#43CD80")))
colored_overlay <- subst(winner_losers_overlay, from, to, names=c("red", "green", "blue"))
colored_overlay_ar <- as.array(colored_overlay)
Convert elevation raster to matrix and plot
elmat = raster_to_matrix(elevation)
elmat %>%
sphere_shade() %>%
add_overlay(overlay=colored_overlay_ar, alphacolor="white",alphalayer = 1) %>%
plot_3d(elmat,zscale=40,zoom=0.85, asp =1.85, phi=20, theta=0,windowsize = 800)
Expected colors:

Result:

Files.zip
The text was updated successfully, but these errors were encountered: