2

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

Do I need to do something else to specify how levels are weighted, or are there arguments I'm missing here?

1 Answer 1

2

The equivalent of terra::plotRGB for leaflet is leafem::addRasterRGB. See https://r-spatial.github.io/leafem/reference/addRasterRGB.html

Example:

library(leaflet)
library(leafem)

leaflet() |> 
  addRasterRGB(plainview::poppendorf, 4,3,2)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.