r - 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)
解决方案
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
to更改为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')
推荐阅读
- merge - Do I need to use WMI in order to merge text files in VBScript?
- javascript - 如何从请求nodejs中获取ip
- python - 如何在excel中划分相同的数据
- android - 如果我在华为设备上运行我的应用程序,则无法收到通知
- selenium - 为什么 Selenium 将 Safari 11 的版本设为 13605?
- javascript - 修复了响应式表的表头不起作用
- java - 我被困在 java 代码中,我不明白为什么它不返回 true
- python-3.x - 如何导入具有我在函数中作为字符串生成的名称的特定文件,并将其内容用作脚本的全局变量
- mysql - 使用字符串 MYSQL 创建日期
- firebase - 为什么 Unity3d 中的所有双精度数都存储在“Firebase 数据库”中,四舍五入到小数点后 4 位?