unique.default(x) 中的错误:unique() 仅适用于 rLiDAR 包中的矢量

Error in unique.default(x) : unique() applies only to vectors in rLiDAR package

我在 rLiDAR 中使用 chullLiDAR2D 函数计算凸包时遇到此错误。有趣的是,在同一 LAS 文件上使用 chullLiDAR3D 计算 3D 凸包时,我没有遇到此错误。我已经发布了代码和 XY_ID 变量以供进一步参考。

谢谢,

#Computing and plotting the 2D-convex hull of a LAS file
#Importing the LAS file
library(rLiDAR)
LAS_File <- system.file("test.las", package = "rLiDAR")
#Read the LAS file
LAS <- readLAS("D:/Summer_2019/NRS_Project/01_data/01_las_2013/test.las", short = TRUE)
#Subsetting the height of the data
XYZ <- subset(LAS[,1:3],LAS[,3] >= 1.37)
#Get the LiDAR clusters
set.seed(1)
clLAS <- kmeans(XYZ, 32)
#Setting the IDs of the points
ID <- as.factor(clLAS$cluster)
#Setting the XYZID input
XY_ID <- cbind(XYZ[,1:2],ID)
summary(XY_ID)
View(XY_ID)
#Calculating the LiDAR convex hull of the clusters
chull_Trees <- chullLiDAR2D(XY_ID)

XY_ID

ID 向量 必须 命名为“id”

这在 chullLiDAR2D 的帮助页面中有一些记录:

参数

xyid    
A 3-column matrix with the x, y coordinates and points id of the LiDAR point cloud.

查看函数本身,“id”是硬编码的。

# chullLiDAR2D #
function (xyid) 
{
    spdfList <- plyr::dlply(as.data.frame(xyid), "id", 
        function(input) { ...

所以,只需将名称从 ID 更改为 id 就可以了。

#Setting the IDs of the points
id <- as.factor(clLAS$cluster)

#Setting the XYZID input
XY_ID <- cbind(XYZ[,1:2], id)

#Calculating the LiDAR convex hull of the clusters
chull_Trees <- chullLiDAR2D(XY_ID)

# Plotting the LiDAR convex hull
library(sp)
plot(SpatialPoints(xyid[,1:2]),cex=0.5,col=xyid[,3])
plot(chullTrees$chullPolygon, add=TRUE, border='black')