r-spatial / leafem

leaflet extensions for mapview
https://r-spatial.github.io/leafem/
Other
108 stars 29 forks source link

NA values as 255 in mouseover (imagequery) using addGeotiff #96

Open szylinski-sa opened 2 days ago

szylinski-sa commented 2 days ago

I'm using addGeotiff to map a masked raster:

leaflet() %>% 
  addProviderTiles("Esri.WorldImagery",
                   group = "Esri imagery") %>% 
  addGeotiff(file = filepath,   #path to a .tif file
             layerId = "tif")

Using the mouse to hover over the raster and get the pixel values is great, and here it correctly returns my 1 and 0 values in the coloured section. However as the image below shows, the value returned for NA pixels is 255. Is it possible to set the value shown to 'NA' here, or turn off the counter entirely as is the case when hovering over a non-raster area?

image

There's also a transparent grid visible for this area which would be nice to be able to hide (though less of an issue than the pixel values).

tim-salabim commented 2 days ago

Can you share the data and the code to reproduce this?

szylinski-sa commented 2 days ago

Data (single tif) zipped here. This has been quickly clipped down in ArcGIS because the data is sensitive but roughly matches the extent shown in the image. it behaves exactly the same - 1s and 0s appear correctly but what should be NA - and are transparent cells - is showing as 255. Edit- and interrogating the file in Arc confirms that the cells outside the 0/1 area are no value.

Code used is as above -

filepath <- "clip.tif"
leaflet() %>% 
  addProviderTiles("Esri.WorldImagery",
                   group = "Esri imagery") %>% 
  addGeotiff(file = filepath,  
             layerId = "tif")
tim-salabim commented 2 days ago

Ok, thanks! The reason for the 255 is that this is the NoData value set in the tif file. I need to think about whether it makes sense to show these as NA in R (it probably does).

This is the relevant part of gdalinfo clip.tif image

szylinski-sa commented 1 day ago

Thanks, had a feeling it was baked into the file somehow. Any advice or workaround for dealing with this in the meantime? E.g terra::values on terra::rast(filepath) returns NA rather than 255 but not sure if that's useful.