使用R

时间:2017-01-19 15:28:25

标签: r gis closest-points spatial-data-frame

我正在尝试使用R进行一些GIS工作。具体来说,我有一个空间点数据框(称为“点”)和一个spatiallinesdataframe(称为“行”)。我想知道每个点最近的线。我这样做:

# make a new field to hold the line ID
points@data$nearest_line <- as.character('')

# Loop through data. For each point, get ID of nearest line and store it
for (i in 1:nrow(points)){
  points@data[i,"nearest_line"] <-
    lines[which.min(gDistance(points[i,], lines, byid= TRUE)),]@data$line_id
}

这很好用。我的问题是我的数据大小。我有4.5米的积分,大约10万行。到目前为止,它已经运行了大约一天,并且只有450万点中的200,000点(尽管计算机相当强大)。

我能做点什么来加快速度吗?例如,如果我在PostGIS中这样做,我会添加一个空间索引,但这似乎不是R中的一个选项。

或许我接近这完全错了?

0 个答案:

没有答案