r - dist2Line 的快速替代方案
问题描述
我有一个巨大的数据集,其中包含空间数据点和空间多边形。我想计算每个点到最近多边形的距离。
我使用了 geosphere 包中的 dist2Line() 。但是时间太长了。
我需要一个更快的 dist2Line() 版本。
任何帮助将不胜感激!
解决方案
你可以尝试并行处理
#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.
推荐阅读
- c# - SSIS 动态表达式
- git - 我可以拉取远程 Git 存储库并获取远程(未提交)的工作更改吗?
- python - 不确定我是否理解 2 个 django 模型之间的依赖关系
- python - 安装 Python 时如何修复错误消息“`brew link` 步骤未成功完成”?
- javascript - Firebase:奇怪的错误:操作已取消
- python-3.x - 运行外部 python 脚本并让控制台显示在 kivy 网格中
- machine-learning - 在 sklearn 中内置的 SVM 中,平方铰链损失函数中包含的预测输出是什么?
- java - 如何测试私有方法是否具有带有名称和类型的字段?
- matlab - 代码中的未知错误,用于找到火箭降落在月球上所需的角度
- c - 将函数转换为 Arm Neon