-
Notifications
You must be signed in to change notification settings - Fork 30
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
How to style rasters added to a leaflet map with addTileFolder
?
#103
Comments
Hi, its a long time since i have looked into |
Hi @tim-salabim , I can't share my actual data, so I've created some dummy data to illustrate the problem with the following code:
Then I fed this into gdal and used:
And the tiled data is here. I then add this dummy data to the map with:
And the map looks like this: So it is styling a bit differently to my previous image, but my question still remains around how to change this styling. |
Thanks, I'll have a look |
Hi @jpd-defra library(leaflet)
library(leafem)
library(raster)
library(colourvalues)
set.seed(42)
xmin <- 400000
xmax <- 600000
ymin <- 0
ymax <- 300000
resolution <- 500
r <- raster(xmn = xmin, xmx = xmax, ymn = ymin, ymx = ymax,
resolution = resolution, crs = CRS("+init=epsg:27700"))
# values(r) <- sample(c(0, 1), ncell(r), replace = TRUE)
values(r) = rnorm(ncell(r), 50, 10)
r_reprojected <- projectRaster(r, crs = CRS("+init=epsg:4326"), method = "ngb")
writeRaster(r_reprojected, "/tmp/binary_raster_epsg4326.tif", format = "GTiff", overwrite = TRUE)
clrs = colourvalues::color_values(values(r))
clrs = t(col2rgb(clrs))
clr_mat = cbind(elevation_value = values(r), clrs)
write.table(clr_mat, file = "/tmp/color_lookup.txt", sep = " ", row.names = FALSE)
## now run these gdal commands
# gdaldem color-relief /tmp/binary_raster_epsg4326.tif /tmp/color_lookup.txt /tmp/binary_raster_epsg4326_clrs.tif
# gdal_translate -of VRT -ot Byte -scale -a_nodata none /tmp/binary_raster_epsg4326_clrs.tif /tmp/temp.vrt
# gdal2tiles.py --zoom=3-10 --processes=8 /tmp/temp.vrt /tmp/dummy_tiles_WGS84
leaflet() %>%
addTiles() %>%
setView(-0.91431, 51.59701, zoom = 7) %>%
addTileFolder(
"/tmp/dummy_tiles_WGS84",
tms = TRUE,
layerId = NULL,
group = NULL,
attribution = NULL,
options = leaflet::tileOptions(),
data = leaflet::getMapData(.)
) If you want to be able to style stuff from the R call, probably best to have a look at
leaflet() %>%
addTiles() %>%
setView(-0.91431, 51.59701, zoom = 7) %>%
addGeotiff(
file = "/tmp/binary_raster_epsg4326.tif"
, colorOptions = colorOptions(
palette = hcl.colors(256, palette = "viridis")
, na.color = "#333333"
)
) Let me know what you think and how I can help. |
Hey @tim-salabim, thanks very much for looking into this and getting back to me. I've got a few thoughts/followups in two areas.
|
Hello,
I've created a set of tiles with
gdal2tiles.py
I can get them to display on the leaflet map withaddTileFolder
, but from the docs can't work out how to style the raster(s). Which options can I use to provide a colour palette?My code looks like this:
And my map looks like this - the raster extent is correct.
If there's a bit more detail to add to the docs, I would be happy to do this in a PR.
Any help much appreciated!
The text was updated successfully, but these errors were encountered: