我有一个点列表P=[p1,...pN],其中pi=(latitudeI,longitudeI)。
使用Python 3,我想找到一个最小的簇集合(P的不相交子集),使得簇中的每个成员与簇中的其他成员之间的距离不超过20公里。
使用Vincenty方法计算两点之间的距离。
为了更具体一些,假设我有一组点,例如
from numpy import *
points = array([[33. , 41. ],
[33.9693, 41.3923],
[33.6074, 41.277 ],
[34.4823, 41.919 ],
[34.3702, 41.1424],
[34.3931, 41.078 ],
[34.2377, 41.0576],
[34.2395, 41.0211],
[34.4443, 41.3499],
[34.3812, 40.9793]])
现在我正在尝试定义这个函数:
from geopy.distance import vincenty
def clusters(points, distance):
"""Returns smallest list of clusters [C1,C2...Cn] such that
for x,y in Ci, vincenty(x,y).km <= distance """
return [points] # Incorrect but gives the form of the output
注意:许多问题涉及地理位置和属性。我的问题仅与位置有关。这是针对纬度/经度,而非欧几里得距离的。有其他相关问题提供了类似的答案,但没有回答我这个问题(很多问题没有解答):
- https://datascience.stackexchange.com/questions/761/clustering-geo-location-coordinates-lat-long-pairs
- https://gis.stackexchange.com/questions/300171/clustering-geo-points-and-export-borders-in-kml
- https://gis.stackexchange.com/questions/194873/clustering-geographical-data-based-on-point-location-and-associated-point-values
- https://gis.stackexchange.com/questions/256477/clustering-latitude-longitude-data-based-on-distance
- 还有更多,但没有一个回答这个问题。