2

I'm new to R and to lidR.

I have LAS files that are already ground classified and I'm attempting to use the method below to classify the vegetation and then write a new LAS file retaining the ground and vegetation classifications. The resulting LAS files end up with every point classified as vegetation.

What am I doing wrong?

Here's my script:

library(lidR)
las <- readLAS("D:/tree-segmentation/test.las", select = "xyzc", filter = "-drop_z_below 0")
las <- segment_trees(las, li2012(R = 3, speed_up = 5))

plot(las, color = "treeID")


vegetation_class = function(Z)
{
  mz = max(Z) 
  if (mz < 10)
    return(LASLOWVEGETATION)
  else if (mz >= 10 & mz < 22)
    return(LASMEDIUMVEGETATION)
  else
    return(LASHIGHVEGETATION)
}



las@data[!is.na(treeID), Classification := vegetation_class(Z), by = treeID]
plot(las, color = "Classification")
writeLAS(las, "D:/tree-segmentation/test-veg-classified.las", index = FALSE)

1 Answer 1

3

segment_tree() segments from top to bottom no matter the class of the points. This means that ground points have also a treeID

las@data[!is.na(treeID) & Classification != LASGROUND, Classification := vegetation_class(Z), by = treeID]
1
  • Thank you! The script works great now with your changes.
    – Steve
    Commented Feb 21, 2021 at 14:52

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.