dist2Line的快速替代品

时间:2019-07-10 15:38:27

标签: r spatial

我有一个庞大的数据集,其中包含空间数据点和空间多边形。我想计算每个点到最近的多边形的距离。

我从geosphere包中使用了dist2Line()。但这需要太长时间。

我需要更快的dist2Line()版本。

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您可以尝试并行处理

#points being the spatialpointsdataframe, and lines being your spatiallinesdataframe
require(parallel)
fun<-function(i) data.frame(dist2Line(points[i,], lines)) #some function like this

cl <- makeCluster(detectCores())
clusterEvalQ(cl, { library("geosphere") }) #don't know what this does, but it's how i learned this. 
clusterExport(cl, c("dist2Line", "points", "lines")) #here you have to include all your objects and functions you want to use, and export them to a cluster, whatever that is.
results <- parLapply(cl,1:length(points),fun=fun) #use parLapply to 'loop' through the points and return a list of dataframes. should be a list.