lacunr is an R package for calculating 3D lacunarityfrom voxel data. It is designed to be used with LiDAR point clouds tomeasure the heterogeneity or “gappiness” of 3-dimensional structuressuch as forest stands. It provides fast C++ functions to efficientlyconvert point cloud data to voxels and calculate lacunarity usingdifferent variants of Allain & Cloitre’s well-known gliding-boxalgorithm.
You can installlacunr from CRAN with:
install.packages("lacunr")Or you can install the development version oflacunrfromGitHub with:
# install.packages("devtools")devtools::install_github("ElliottSmeds/lacunr")The standard workflow forlacunr is fairly simple:
voxelize()bounding_box()lacunarity()library(lacunr)# create a data.frame of simulated point cloud datapc<-data.frame(X =rnorm(1000,10),Y =rnorm(1000,50),Z =rnorm(1000,25))# convert to voxels of size 0.5vox<-voxelize(pc,edge_length =c(0.5,0.5,0.5))# generate binary mapbox<-bounding_box(vox)# calculate lacunarity curvelac_curve<-lacunarity(box)lidRThelidrpackage offers a robust suite of tools for processing LiDAR data.Whilelacunr does not requirelidR as adependency, it is assumed that most users will be working with pointcloud data imported usinglidR, and the package is designedto mesh well withlidR’s data objects. The following tipswill help make combining these packages as seamless as possible.
LASobjectsUsers should take special care when using alidRLAS object as input for thevoxelize()function. SinceLAS is an S4 class, it is important toextract the point cloud data from theLAS object using@data, otherwisevoxelize() will throw anerror:
library(lidR)# read in LAS point cloud filelas<-readLAS("<file.las>")# voxelize the LAS point cloud, taking care to input the correct S4 slotvox<-voxelize(las@data,edge_length =c(0.5,0.5,0.5))lidRlidR offers its own extremely versatile voxelizationfunction,voxel_metrics().This provides a useful alternative tovoxelize(), althoughit is important to note that both functions utilize different algorithmsand will not produce identical results (see the following section formore details).
voxel_metrics() returns alasmetrics3dobject.lacunr’sbounding_box() function canaccept this as an input, but it also requires that it contain a columnnamedN, recording the number of points in each voxel. Thiscolumn can be generated byvoxel_metrics() using thefollowing:
# read in LAS point cloud filelas<-readLAS("<file.las>")# voxelize at 1m resolution, creating a column N containing the number of pointsvox<-voxel_metrics(las,~list(N =length(Z)),res =1)# convert to arraybox<-bounding_box(vox)voxelize() vslidR::voxel_metrics()voxelize() is adapted from the functionvoxels(), originally written by J. Antonio Guzmán Q. forthe packagerTLS. It isintended as a complement rather than a replacement forlidR’s more elaboratevoxel_metrics(). Eachfunction has a different underlying algorithm and will produce distinctresults from the same input data. The chief advantages ofvoxelize() overvoxel_metrics() are:
voxel_metrics() permits at most twodimensions.voxel_metrics(). This is due to differences in how eachfunction aligns the point cloud data within the voxel grid.