【问题标题】:fast alternative to dist2Linedist2Line 的快速替代方案
【发布时间】:2019-07-10 15:38:27
【问题描述】:

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

我使用了 geosphere 包中的 dist2Line()。但是时间太长了。

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

任何帮助将不胜感激!

【问题讨论】:

    标签: r spatial


    【解决方案1】:

    你可以试试并行处理

    #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. 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-14
      • 2021-09-11
      • 1970-01-01
      • 2013-10-03
      • 1970-01-01
      相关资源
      最近更新 更多