向列表中添加元素失败

Failure in adding an element to a list

大家早上好! 我和一位同事在使用简单脚本时遇到了一些问题。我们想从 LiDAR 数据中提取树木的树冠几何形状。我们正在使用 itcSegment 库。考虑到我们正在处理大型数据集,我们创建了一个循环,以便模型处理低负载数据。每个循环都应将输出添加到列表中,但是,当循环停止时,列表仅在最后一个位置显示一个元素,其他所有元素都是空的... 我们不知道为什么,这是我们的代码:

library(itcSegment)
library(dplyr)

dataset=read.table(file ="dataset_test5.txt",header = T,sep = "\t")

k=1
i=1
j=round(nrow(dataset)/10000)
output.list=list()
for (i in j) { 
      subdata<-slice(dataset,k:(k+9998))
      se1<-itcLiDAR(subdata$X,subdata$Y,subdata$Z,epsg = 32632,resolution = 1,
         MinSearchFilSize = 5, MaxSearchFilSize = 11, TRESHSeed = 0.55,
         TRESHCrown = 0.6, minDIST = 5, maxDIST = 40, HeightThreshold = 10,
         cw = 1)
      k=(k+9999)
      output.list[[i]]=se1
      plot(se,axes=T,add=T)
      }

应该很简单,但我们还是R初学者。 感谢您的任何建议

我使用 R 内置数据集尝试了以下代码 lasData

library(itcSegment)
library(dplyr)

dataset <- lasData # Using R inbuilt data

Seq_Len <- round(seq(1, nrow(dataset) + 1, length.out = round(nrow(dataset) / 4227))) # Here instead of 4227 you may use 10000 as needed

output.list=list()
for (i in 1:(length(Seq_Len) - 1)) { 
  print(paste0(i, 'th iteration started')) # To monitor the iteration
  subdata <- slice(dataset, Seq_Len[i]:(Seq_Len[i+1] - 1))
  se1 <- itcLiDAR(subdata$X, subdata$Y, subdata$Z, epsg = 32632, resolution = 1, 
                  MinSearchFilSize = 5, MaxSearchFilSize = 11, TRESHSeed = 0.55, 
                  TRESHCrown = 0.6, minDIST = 5, maxDIST = 40, HeightThreshold = 10, cw = 1)
  output.list[[i]]=se1
}

output.list

[[1]]
class       : SpatialPolygonsDataFrame 
features    : 6 
extent      : 676769.2, 676787.9, 5091691, 5091719  (xmin, xmax, ymin, ymax)
crs         : +init=epsg:32632 
variables   : 5
names       :         X,          Y, Height_m, ID,            CA_m2 
min values  : 676772.33, 5091693.65,    29.98,  1, 27.8797000015035 
max values  : 676784.46, 5091715.39,    40.42,  6, 72.9472500010449 

[[2]]
class       : SpatialPolygonsDataFrame 
features    : 5 
extent      : 676764.1, 676787.7, 5091691, 5091719  (xmin, xmax, ymin, ymax)
crs         : +init=epsg:32632 
variables   : 5
names       :         X,          Y, Height_m, ID,            CA_m2 
min values  : 676768.28, 5091693.56,    23.82,  1, 3.53379999986505 
max values  : 676785.18, 5091714.86,    40.56,  5, 63.4798499996493 

[[3]]
class       : SpatialPolygonsDataFrame 
features    : 5 
extent      : 676762.4, 676780.6, 5091691, 5091719  (xmin, xmax, ymin, ymax)
crs         : +init=epsg:32632 
variables   : 5
names       :         X,          Y, Height_m, ID,            CA_m2 
min values  : 676766.47, 5091693.16,    30.21,  1, 26.2325500003377 
max values  : 676778.09, 5091715.51,    33.85,  5, 81.5636000017628