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

addCOG #65

Open
frzambra opened this issue Mar 26, 2023 · 1 comment
Open

addCOG #65

frzambra opened this issue Mar 26, 2023 · 1 comment

Comments

@frzambra
Copy link

frzambra commented Mar 26, 2023

I'm testing addCOG with some data I have in an AWS S3 bucket. I tried to follow to the examples on other issues but cannot get a colored map, all I can get is a gray scale.

url <- 'https://chelsa-chile.s3.amazonaws.com/monthly/pet/CHELSA_pet_v2.1_19790201.tif'

min_scale = 0; max_scale = 1
js_scale = paste0("function (values) {
                    var scale = chroma.scale(['white', '#22c7e8']).domain([", min_scale, ",", max_scale, "]);
                    var val = values[0];
                    if (val === 0) return;
                    if (val < 0) return;
                    return scale(val).hex();
                    }")

leaflet(options = leafletOptions(attributionControl = FALSE)) %>% 
  setView(lng =-70.09635, lat =  -33.01703, zoom = 4) %>% 
  addProviderTiles("Esri.WorldImagery", group = "esri") %>%
  addMapPane("cog", zIndex = 500) %>%
  leafem:::addCOG(
    url = url
    , group = "PET"
    , opacity = 0.7
    , options = list(pane = "cog")
    # , resolution = 96
    , autozoom = FALSE
    , colorOptions = colorOptions(
      palette = terrain.colors(256)
    )
    , pixelValuesToColorFn = JS(js_scale)
  ) %>%
  addMouseCoordinates() %>%
  addLayersControl(
    baseGroups = c("esri")
    , overlayGroups =  c("PET")
  )

Also, I developed a shiny app to test addCOG and addGeoRaster which is in https://frzambra.shinyapps.io/visraster_app/

Any thoughts?

@trafficonese
Copy link
Contributor

maybe try to change the min/max_scale values and the js_scale function.
The data has a pretty wide range (from -2000000000 to 150000).

I get a colored image with:

min_scale = 0; max_scale = 100000
js_scale = paste0("function (values) {
                    var scale = chroma.scale(['white', 'red', 'yellow', '#22c7e8']).domain([", min_scale, ",", max_scale, "]);
                    var val = values[0];
                    if (val === 0) return;
                    if (val < 0) return;
                    return scale(val).hex();
                    }")

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