首页 > 解决方案 > unique.default(x) 中的错误:unique() 仅适用于 rLiDAR 包中的向量

问题描述

使用 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 在此处输入图像描述

标签: rlidarlidar-data

解决方案


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) { ...

因此,只需将名称从IDto更改为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')

在此处输入图像描述


推荐阅读