# NOT RUN {
#- import the tree_line_plot dataset
file = system.file("extdata", "tree_line_plot.laz", package="viewshed3d")
tls = lidR::readLAS(file,select="xyz")
#- remove noise to avoid visibility estimates error
tls_clean <- viewshed3d::denoise_scene(tls,method="sd",
filter=6)
#- RECONSTRUCT THE GROUND
#- classify ground points
class=lidR::classify_ground(tls_clean, lidR::csf(rigidness = 1L,
class_threshold = 0.1,
sloop_smooth = TRUE), FALSE)
#- reconstruct the ground. No need for a very fine ground reconstruction.
ground = lidR::grid_terrain(class, 0.05, lidR::knnidw())
#- build the final scene
reconstructed = na.omit(raster::as.data.frame(ground, xy = TRUE))
names(reconstructed)=c("X","Y","Z")
recons=rbind(lidR::LAS(na.omit(reconstructed)),tls_clean)
#- CREATE THE POSITIONS WITH RANDOM POINTS
N_positions = 10 #- how many points ?
height = 2 #- points height relative to the ground
positions=data.table::data.table(reconstructed[runif(N_positions,
1,nrow(reconstructed)),])
positions[,Z:=Z+height]
#- compute the cumulated viewsheds from the positions
cumulated=viewshed3d::viewsheds(data=recons,
positions = positions ,
angular_res = 1,
vox_res = 0.2)
#- plot the result
x=lidR::plot(cumulated,color="N_visible",size=3,
colorPalette=viridis::cividis(nrow(positions)+1),trim=6)
#- add the positions
lidR::add_treetops3d(x,sp::SpatialPointsDataFrame(positions,positions),
radius=0.5,col="red",add=TRUE)
# }
Run the code above in your browser using DataLab