Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaflet muddling RGB rasters from terra #900

Open
jebyrnes opened this issue Jan 2, 2024 · 1 comment
Open

Leaflet muddling RGB rasters from terra #900

jebyrnes opened this issue Jan 2, 2024 · 1 comment

Comments

@jebyrnes
Copy link

jebyrnes commented Jan 2, 2024

I'm working with an RGB raster in leaflet (some Landsat data). I'm stretching and sampling it down so that it's small enough. The following works great.

# stretch and then resample like geom_spatraster
landsat_rgb_stretched <- stretch(landsat_colors_1230[[1:3]],
                                 minq = 0.02, maxq = 0.98) |>
  spatSample(size = 5e5, as.raster = TRUE, method = "regular")

# set RGB channels
RGB(landsat_rgb_stretched) <- 3:1

# plot
plotRGB(landsat_rgb_stretched)

image

But, when I try and put it into leaflet, I get a muddled mess. It's close, but, very weird. I'm trying to figure out why.

# interactive plot
leaflet() |>
  addRasterImage(landsat_rgb_stretched)
image
@aloboa
Copy link

aloboa commented Jul 3, 2024

I have a similar problem using an slightly different approach:

r <- subset(rast("enmapL2A_199-114-037_gmap.tif"),1:3)
RGB(r) <- 1:3
r[r==0] <- NA
a <- colorize(r,"col")
plot(a)

Then I use
addRasterImage(a, group="a")

And the colors and grain are much worse than in the R plot() (left):
image

Instead, the display with 1 single band is ok:

r1 <- r[[1]]

addRasterImage(r1, group="r1")

image

(do not manage to get the same color table, but the leaflet display on the right is not grainy as in the previous case)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants