Your point cloud is likely to have a shape that is complex and not square, rectangular or convex (hard to say in your image). Below a point-cloud of mine seen from above.
I don't know how lastools
estimate the density (we must dig in the source code to know) but in all case it is an estimate and many results are valid depending on how you compute the area covered by the point cloud.
In the above point-cloud we can estimate the density with:
- The number of points divided by the area of the bounding box. This is inaccurate if the point cloud is not rectangular
density(las@header)
#> [1] 1.74
- To be more accurate
lidR
computes the convex hull of the point cloud and uses the area of this polygon as denumerator.
density(las)
#> [1] 2.71
- To be more accurate we can use a concave hull. lidR does not do that by default because it is computationally demanding but I can do it with internal tools. In this case I get
3.21
- We can also use a raster-based approach by rasterizing the density and computing the average
d = grid_density(las)
mean(d[d>0])
#> [1] 3.13
- With
lastools
, for my point-cloud I get 3.18
.
The points 3,4 and 5 are relatively close so we can suppose that the method in lastools
is somehow based on the computation of complex hulls or on a raster-based method.
Edit based on lasinfo
source code I was able to reproduce lastools
output with lidR
d = grid_density(las, 2)
> mean(d[d>0])
[1] 3.18
Which is a solution that does not work for low density point cloud or longlat point-clouds