PredictiveEcology / wbi_shiny

https://wbi-nwt.analythium.app
GNU General Public License v2.0
0 stars 1 forks source link

TMS file updates #10

Closed psolymos closed 2 years ago

psolymos commented 2 years ago

Explore if allowing multiple palettes in a TMS framework is feasible or not. (Alternative is to use COGs and define palette on the fly.)

psolymos commented 2 years ago

The GeoTIFF approach is promising. Battling transparency and CORS, but here it is (using a test API here because GitHub pages has CORS headers):

library(shiny)
library(leaflet)
library(leafem)

## note Leaflet is having problem with CORS requests
shinyApp(
  ui=fluidPage(
    leafletOutput("map")
  ),
  server=function(input, output) {
    output$map <- renderLeaflet({
      leaflet() %>%
        addProviderTiles("Esri.WorldImagery") %>%
        addGeotiff(
          url = "https://peter.solymos.org/testapi/amro1k.tif",
          project = FALSE,
          opacity = 0.8,
          colorOptions = colorOptions(
             palette = hcl.colors(50, palette = "inferno"), 
             domain = c(0, 0.62),
             na.color = "transparent"))
    })
  }
)

Note the mapping of the palette to the domain. This would really help in applying custom color scales and comparing among periods/scenarios.

Here is what I get: transparency is an issue with finding noDataValue in the JS code

Screen Shot 2022-03-11 at 7 59 00 PM
psolymos commented 2 years ago

Solution: write TIF using {stars}:

library(stars)
s <- st_as_stars(r)
write_stars(s, "filename.tif")
psolymos commented 2 years ago

Update: color palettes were ranked based on 9 poll responses

Decision: use spectral (grDevices::hcl.colors(n, "spectral", rev = TRUE)).