I'm using LAScatalog
with an area based approach for tree detection.
Ultimately, I want to merge the trees and tree height information into a single data frame for subsequent analysis. But I did not find a convenient way to relate trees and tree height values to the plots that they belong to (e.g., treeID 1 has Z value of 10, but which plot does it belong to?).
Is there a simple way to add .las/.laz filename (or some intuitive ID) as attribute in the shapefile output?
My current solution is as follows:
library(lidR)
library(sf)
library(tidyverse)
# read catalog
ctg <- readLAScatalog("folder/")
# set las catalog options
opt_independent_files(ctg) <- TRUE
opt_output_files(ctg) <- "output/trees/plot_{ID}"
# run tree detection (outputs shapefiles)
ttops <- find_trees(ctg, lmf(ws = 5))
# create a list of shapefiles
file_list <- list.files(here("output/trees/"), pattern = "*shp", full.names = TRUE)
# read in the list of shapefiles
shapefile_list <- lapply(file_list, read_sf)
# convert shapefile list to single data frame
trees <-
shapefile_list %>%
lapply(st_drop_geometry) %>% # converts to dataframe
bind_rows(.id="plot")