The Intensity
int column has the ability to store all the treeID
values. There is a slightly different format for copying rows to another and you can find the locations using str(las1)
. Additionally, some NA
values were discovered from points not allocated, which I have remedied below as this initially failed to enable writing the .las successfully. Once imported into ArcPro adjust the Symbology to draw using intensity creating a custom Value Source and random Color scheme setting your max number of of identified trees value as highlighted in the screenshot, this gave better visual results showing less adjacent trees being coloured similarly. The data clearly displays individual trees satisfactorily with some adjustment lowering the Symbol scale.
library(lidR)
library(dplyr)
# Import the las and segment the trees
LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las <- readLAS(LASfile)
las1 <- segment_trees(las, li2012())
# remove points that are not assigned to a tree
trees = filter_poi(las1, !is.na(treeID)) # remove NA
col <- random.colors(100)
plot(trees, color = "treeID", colorPalette = col)
# format for copying rows to overwrite
las1$Intensity = las1$treeID
head(trees) # checking first few rows copied
trees = filter_poi(las1, !is.na(Intensity)) # remove all NA values from here too
writeLAS(las = trees, file = "ntrees.las")
max(trees$Intensity, na.rm = TRUE) # check max number of identified trees
Screenshot below of my zoomed ArcPRO working with less than 65,535 treeID (Intensity attribute is 16 bits) from the above code but loading a significantly larger.las file than the example, this consisted of 130 Mb or 30 million data points consisting of 4532 trees.