I would like to extract a set of (x, y, z) based metrics from a lidar point cloud using the R lidR package. These metrics should be extracted for each field plot, the locations of which are in a shapefile. Each plot is represented by a 15m circular feature, in the shapefile.
I wrote the following code and it executes without any error messages. However, I am unsure if I am using the "~" based notation correctly. So, can you check if it is okay?
require(lidR)
require(sf)
myMetrics <- function(x, y, z, Intensity, ReturnNumber, Classification, dz)
{
# ms1: metric set 1
ms1 <- stdmetrics_z(z)
ms2 <- stdmetrics_ctrl(x, y, z)
ms3 <- stdshapemetrics(x, y, z)
return (c(ms1, ms2, ms3))
}
# fieldPlots: Shapefile containing the location of the (15m size/circular) field plots.
fieldPlots <- st_read("plots.shp")
lasData <- lidR::readLAS("ALS_data.las")
d <- polygon_metrics(lasData, func = ~myMetrics(X, Y, Z, Intensity, ReturnNumber, Classification, dz=1), fieldPlots)
Can you also provide more information about how the code line with the polygon_metrics function call works? That is, how do the variables X, Y, Z etc get their values?