1

I want to add segments represent the tree of apex tree, how to add segments3d to the plot below ?

library(lidR)
library(rgl)

LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las <- readLAS(LASfile, select = "xyz", filter = "-drop_z_below 0")

ttops <- tree_detection(las, lmf(ws = 5))

plot(las) %>%
  add_treetops3d(ttops) %>%
  segments3d(...)

What are arguments of ... ?

1
  • 1
    I guess that you want to plot tree trunks?
    – JRR
    Commented Feb 27, 2020 at 15:00

1 Answer 1

2

The key point here is that the point cloud is not rendered with actual XY coordinates because rgl is working with float instead of double and this create artifacts when displaying the point cloud. The coordinates are thus shifted to get a nice rendering.

To display your segments you must shift their coordinates as well. plot returns the offset values applied. In the following example I assumed that you wanted to plot the trunks of the trees

library(lidR)
library(rgl)

LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las <- readLAS(LASfile, select = "xyz", filter = "-drop_z_below 0")

ttops <- tree_detection(las, lmf(ws = 5))

x = coordinates(ttops)[,1]
y = coordinates(ttops)[,2]
z = ttops$Z

offset = plot(las)
add_treetops3d(offset, ttops)

xoffset = offset[1]
yoffset = offset[2]

for (i in 1:length(ttops))  
{
  X = c(x[i], x[i]) - xoffset
  Y = c(y[i], y[i]) - yoffset
  Z = c(0, z[i])
  segments3d(X, Y, Z, col = "white", size = 2)
}
0

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.