terrain layer
https://github.com/visgl/deck.gl/blob/master/docs/layers/terrain-layer.md
TODO
- [ ] examples of loading various DEMs
Proof of concept
mapdeck() %>%
add_terrain()

pushed to master for people to use / test.
Hello, I'm trying to use add_terrain but can't to get a terrain file (png) located somewhere else to work, see the example below.
The terrain.png and mask are the same files used in the example document
elevation <- "file:///home/Downloads/terrain.png"
texture <- "file:///home/Downloads/terrain-mask.png"
mapdeck() %>%
add_terrain(
, elevation_data = elevation
, elevation_decoder = c(1,0,0,0)
, texture = texture
, bounds = bounds
, max_error = 1
)
taking examples from
- https://github.com/visgl/deck.gl/issues/5121
- https://stackoverflow.com/a/33410766/4002530
you need to encode the files. Here's a working example
library(RCurl)
elevation <- normalizePath( '~/Downloads/terrain.png')
texture <- normalizePath('~/Downloads/terrain-mask.png')
txt <- base64Encode(readBin(elevation, "raw", file.info(elevation)[1, "size"]), "txt")
elevation_data <- sprintf("data:image/png;base64,%s", txt)
txt <- base64Encode(readBin(texture, "raw", file.info(texture)[1, "size"]), "txt")
texture_data <- sprintf("data:image/png;base64,%s", txt)
## image = 'data:image/jpeg;base64,'+ str(base64.b64encode(open("/path/to/file", "rb").read()).decode('utf-8'))
bounds <- c(-122.5233, 37.6493, -122.3566, 37.8159)
library(mapdeck)
set_token(secret::get_secret("MAPBOX"))
mapdeck() %>%
add_terrain(
, elevation_data = elevation_data
, elevation_decoder = c(1,0,0,0)
, texture = texture_data
, bounds = bounds
, max_error = 1
)
Excellent, thanks!
you could probably simplify the string encoding with base64enc::base64encode("file.png")
That worked, but I'm still having issues trying to load in a different elevation png. I'm trying to make a bathymetric terrain using the marmap package like so:
library(marmap)
b <- getNOAA.bathy(lon1 = -74.24547803104537, lon2 = -73.27730792856238, lat1=40.291108390496284,
lat2 = 40.68746589140695, resolution = 0.1)
r <- as.raster(b)
png(file = "myplot.png", bg = "transparent")
raster::plot(r, maxpixels=ncell(r), col=hcl.colors(24, palette = "Blues 2"),
axes=FALSE, box=FALSE, legend=FALSE)
dev.off()
This saves a png. But then I try and use this in add_terrain() :
elevation <- normalizePath( "myplot.png")
texture = normalizePath( "myplot.png")
elevation_data <- sprintf("data:image/png;base64,%s", base64enc::base64encode(elevation))
texture_data <- sprintf("data:image/png;base64,%s", base64enc::base64encode(texture))
bounds <- c(r@extent@xmin, r@extent@ymin, r@extent@xmax, r@extent@ymax)
mapdeck() %>%
add_terrain(
, elevation_data = elevation_data
, elevation_decoder = c(1,0,0,0)
, texture = texture_data
, bounds = bounds
, max_error = 1
)
It doesn't render anything, am I missing something?
Alternatively, is there a way to load in base service layers from mapbox? I found this one: https://docs.mapbox.com/data/tilesets/reference/mapbox-bathymetry-v2/
But I'm not sure how to use that.