我是R的新手。我想读取LAS文件并执行一些操作,然后通过以下代码将结果保存为.csv文件。但是,输出文件另存为输入文件格式(LAS)。非常感谢您的帮助。
library(lidR)
files <- list.files(path= "Input_path", pattern= "*.las", full.names = TRUE, recursive = FALSE)
O <- function(x) {
las = readLAS(x, select = "xyz", filter = "keep_first -drop_z_below 0")
data <- as.spatial(las)
z <- data$Z
q <- quantile(z, 0.99)
data1 <- subset(data,data$Z <= q)
return(data1)
}
for (f in files) {
print(f)
data2 <- O(f)
write.csv(data2, file = paste0("PATH/", basename(f)))
}
答案 0 :(得分:1)
尝试此操作,文件名应为csv
write.csv(data2, file = paste0("PATH/",unlist(strsplit(basename(f),"[.]"))[1],".csv"))
编辑
如果文件名具有“。”名称中间,可以使用此方法
for (f in files) {
print(f)
data2 <- O(f)
s = unlist(strsplit(basename(f),"[.]"))
filename <- paste0(paste0(s[1:length(s)-1], collapse = "."),".csv")
write.csv(data2, file = paste0("PATH/", filename))
}