The problem of point_metrics() is that it calls user's R code millions of times and this have a cost. Moreover it cannot be safely multithreaded. The function is good for prototyping but for production you must write your own code. For example you can reproduce the function segment_shape() with point_metrics() but segment_shape() is pure C++ and multi-threaded and is often an order of magnitude faster.
Let try with ~3 millions points. The two examples are not equivalent (different output) but the computation load is almost the same (eigen value decomposition).
system.time({point_metrics(cloud_raw, .stdshapemetrics, k = 20)})#> 110 secondsset_lidr_threads(4L)system.time({segment_shapes(cloud_raw, shp_plane(k = 20))})#> 17 secondsAlso you may be advised to use the adequate function readLAS() as a function of your point-cloud. The previous examples, if read with readTLSLAS(), take 190 and 50 seconds respectively because my point-cloud is ALS. But if you are working with TLS you are better to use readTLSLAS().
Also .stdshapemetrics is nothing else than a wrapper around the C++ you already found. No gain expected.
As a conclusion:
- Write your own C++ code. Take inspiration from
lidRsource code of segment_shape - Use lidR spatial index C++ API to reprocuce lidR code.
- Ask lidR questions on https://gis.stackexchange.com/questions/tagged/lidr with the tag
lidr
Or go on the lidR repo and ask for a new feature of a native fast eigen value decomposition.







