2

The rayshader package in R allows beautiful 3D modeling in R. Now I was trying to first try and overlay a LAS file on top of a base-map which is a Rayshader array object. I was trying %>% to link the two objects but it doesn't overlay the two objects in the RGL window and I get an error. The purpose is to do 3D LiDAR modeling. Can something similar to this be achieved?

To create a base-map using rayshader, I first took a digital terrain model (DTM) raster, second converted it to a raster and then:

TLS_LAS_DTM = raster("~/DTM_Raster/tls_las_dtm.tif")    

# Use the Rayshader package
library(magick)
TLS_LAS_DTM_mat = raster_to_matrix(TLS_LAS_DTM )

TLS_LAS_Basemap = TLS_TP1_DTM_mat %>% 
  height_shade() %>% 
  add_shadow(lamb_shade(TLS_LAS_DTM_mat ,zscale = 6),0) %>%
  add_overlay(sphere_shade(TLS_LAS_DTM_mat , texture = "desert", 
                           zscale=4, colorintensity = 5), alphalayer=0.5) %>% 
  add_shadow(ambient_shade(TLS_LAS_DTM_mat ), 0) %>%
  add_shadow(texture_shade(TLS_LAS_DTM_mat ,detail=8/10,contrast=9,brightness = 11), 0.1)

Then I took a LAS object (data.frame/data.table) which was tree segmented using silva2016 method and passed it to the plot function to open it in an RGL window.

plot(TLS_LAS.ITD.dalponte.p2r) %>% 
TLS_LAS_Basemap %>% 
  plot_3d(TLS_LAS_DTM , windowsize=c(1200,800))
#> Error in plot_3d(., TLS_TP1_DTM_mat, windowsize = c(1200, 800)) : 
#> Argument `hillshade` must not contain any entries less than 0 or more than 1

The base-map looks like this

enter image description here

1 Answer 1

5

You can use rayshader::render_points(). Below a fully reproducible example with a point cloud on top of a rayshaded DTM

library(lidR)
LASfile = system.file("extdata", "Topography.laz", package="lidR")
las = readLAS(LASfile)
dtm = grid_terrain(las, algorithm = tin()) # RasterLayer
bbox <- extent(dtm)

library(rayshader)
elmat = raster_to_matrix(dtm)

x = elmat %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(elmat), color = "desert") %>%
  add_shadow(ray_shade(elmat, zscale = 3), 0.5)

pal <- colorRampPalette(height.colors(10))
col <- pal(30)[as.numeric(cut(las$Z, breaks = 30))]

x %>% plot_3d(elmat, zscale = 1, fov = 0, theta = 135, zoom = 0.75, phi = 45, windowsize = c(800, 800))
render_points(extent = bbox, long = las$X, lat = las$Y, altitude = las$Z,size = 2, color = col)

enter image description here

2
  • How can I add the axes and axes labels, as functions axes3d and title3d are no available in rayshader? Commented Jun 21, 2021 at 3:36
  • 1
    These fonctions are from rgl
    – JRR
    Commented Jun 21, 2021 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.