0

我需要循环加载 SpatialPolygonDataFrames 。这些是通过缓冲道路文件创建的。但是,由于我的 SpatialLinesDataFrame 类的“道路”文件长 15000 行,因此 rbind 函数会逐渐变慢。如果它们是数据框,我会使用 rblindlist 来加快速度。但这不适用于 sp 对象(对吗?)。有人有好主意吗?

for (i in 1:nrow(roads)) {

  temp <- gDifference(gBuffer(roads[i,], byid = T, width =  15, capStyle = 'ROUND'), 
                  gBuffer(roads[i,], byid = T, width =  10, capStyle = 'ROUND'))

  slot(slot(temp, "polygons")[[1]], "ID") <- as.character(roads[i,]$oid)

  if (i == 1) {difference <- temp}

  if (i > 1) {difference <- rbind(difference, temp)}

  rm(temp)
  print(i)

}

谢谢

詹姆士

4

1 回答 1

1

我不确定你是否需要循环。你可以使用 package sf。这是您想要实现的(我认为)的示例:

library(mapview) # for the example lines data
library(sf)
trails$diff = st_geometry(st_buffer(trails, dist = 1500)) / st_geometry(st_buffer(trails, 1000))
mapview(trails$diff)

这是你想要的结果吗?如果没有,您可能希望提供一个可重现的示例。

于 2018-05-16T10:13:47.920 回答