Rayshader Adventure: Tahoe

Eric Samson | 10.25.2019

3DEP Data Visualized in ArcGIS

In some situations, 3D visuals can be distracting and/or misleading. However, when done correctly, they can be attention grabbing and insightful in ways that a 2D map or plot can't be. In the past, I have made 3D products using QGIS and Blender. When I first saw the examples created using the Rayshader library, I knew I had to give it a try. I gathered my own DEM data and created a mosaic of some tiles in ArcGIS Pro. The DEM that I created ended up being extremely large and R studio didn't handle it very well (understandably). The final version of this DEM can be seen at the top of this page. I decided to look into some alternatives.

I found an R package that works great in tandem with rayshader. Geoviz can grab DEM's from mapzen, satellite imagery tiles from mapbox, and basemaps from Stamen maps. I chose the center of Lake Tahoe for this visualization and then added some labels in photoshop. The R code with instructions can be found on the bottom of this page.

Tahoe Ski Resorts

Here's the R code:

##Lat, long of the area you want(Tahoe Center)
lat <- 39.087018
long <- -120.036400
square_km <- 30

##~Set max tiles. This sets the resolution of your DEM. 
##The max is 60, but the image will be slower in R (TEST ON 10)
max_tiles <- 10

#DEM data from Mapzen
dem <- mapzen_dem(lat, long, square_km, max_tiles = max_tiles)

# If you want to put satellite imagery on, first get a mapkey
# MapKey: https://docs.mapbox.com/help/glossary/access-token
mapbox_key <- "Your Key"
#add this option to the following slippy_overlay: api_key = mapbox_key
# or use a Stamen basemap, like I did in this example:
overlay_image <-
    image_source = "stamen",
    image_type = "terrain-background",

sunangle <- 270

#Draw the rayshader scene
elmat = matrix(
  raster::extract(dem, raster::extent(dem), method = 'bilinear'),
  nrow = ncol(dem),
  ncol = nrow(dem) )

#Rayshader texture:
elmat %>%
  sphere_shade(texture = "bw") %>%

#plot map with overlay image and shadows
elmat %>%
    sphere_shade(texture = "bw") %>%
     add_overlay(overlay_image,alphalayer = 1) %>%
    add_shadow(ray_shade(elmat, zscale=50,maxsearch = 500)) %>%

#render in 3d
elmat %>%
    sphere_shade(texture = "bw") %>%
    add_overlay(overlay_image,alphalayer = 0.6) %>%
    plot_3d(elmat, zscale = 15, fov = 0, theta = -15, zoom = 0.58, phi = 38, windowsize = c(1000, 800))

Email me