【发布时间】:2020-04-24 13:39:33
【问题描述】:
我在名为 person_location 的数据框中有一组经度/纬度点
+----+-----------+-----------+
| id | longitude | latitude |
+----+-----------+-----------+
| 1 | -76.67707 | 39.399754 |
| 2 | -76.44519 | 39.285084 |
| 3 | -76.69402 | 39.36958 |
| 4 | -76.68936 | 39.369907 |
| 5 | -76.58341 | 39.357994 |
+----+-----------+-----------+
然后我在一个名为building_location的数据框中有另一组经度和纬度点:
+----+------------+-----------+
| id | longitude | latitude |
+----+------------+-----------+
| 1 | -76.624393 | 39.246464 |
| 2 | -76.457246 | 39.336996 |
| 3 | -76.711729 | 39.242936 |
| 4 | -76.631249 | 39.289103 |
| 5 | -76.566742 | 39.286271 |
| 6 | -76.683106 | 39.35447 |
| 7 | -76.530232 | 39.332398 |
| 8 | -76.598582 | 39.344642 |
| 9 | -76.691287 | 39.292849 |
+----+------------+-----------+
我要做的是计算person_location 中的每个ID,building_location 中最接近的ID。我知道如何使用来自library(geosphere) 的distHaversine 函数计算两个独立点之间的差异,但是我如何让它来评估从一个点到一组多个点的最近距离?
【问题讨论】:
-
每个data.frame有多少行?
-
我假设您正在寻找的答案是
person_location中的五 (5) 和building_location中的九 (9) -
建议重复:Geographic / geospatial distance between 2 lists of lat/lon points (coordinates)。
geosphere::distm()会给你一个距离矩阵,然后你从每一列或每一行中选择最小值。 -
我实际上是在寻找完整数据集中的数字,因为这将决定任何解决方案的性能
-
@SymbolixAU 我对此很陌生,所以请原谅我听起来毫无头绪,但是完整数据集是什么意思?这些只是我制作的示例帧。
标签: r geospatial sf geosphere