I have done a individual tree segmentation using lidR and the resulting LAS file now has been classified so that all points belonging to a tree have a unique treeID. So far so good!

But before writing the LAS file I would like to add High, Medium and Low vegetation to the trees as well. So for example if a tree have a height of let say 5 meter it should be classified as Low vegetation (classification = 3) and between 5 to 10 meters should be classified to Medium vegetation (classification = 4) and so on. I cant figure out how to do it, is this possible using lidR?

1 Answer 1


There is no such built-in tools in lidR but we can use data.table native syntax.

  1. Segmentation using the example in the manual
LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las <- readLAS(LASfile, select = "xyzc", filter = "-drop_z_below 0")
las <- segment_trees(las, li2012(R = 3, speed_up = 5))
plot(las, color = "treeID")
  1. Define a function to attribute a class to each tree (here I chose thresholds to generate a good looking picture).
vegetation_class = function(Z)
  mz = max(Z) 
  if (mz < 10)
  else if (mz >= 10 & mz < 22)
  1. Apply this function by treeID. The former classification is preserved for points that are not trees
las@data[!is.na(treeID), Classification := vegetation_class(Z), by = treeID]
plot(las, color = "Classification")

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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