我有一个带有坐标和网络ID的位置列表
SC NETWORK_ID Lat Lon
0 ED0002 41.6742 26.553130600000003
0 ED0016 41.7750556 26.9170278
0 IS0030 41.05455556 28.80925
0 IS0134 40.97616944 28.80165
1 ED0016 41.7750556 26.9170278
1 IS0096 40.99406111 28.82413056
1 IS0137 40.98033889 28.73052778
1 IS0280 41.1085556 28.874861100000004
2 ED0002 41.6742 26.553130600000003
2 ED0018 41.26675 26.687669399999997
2 IS0034 41.10741944 28.80134167
2 IS0063 40.97868889 28.72448889
2 IS0280 41.1085556 28.874861100000004
2 IS0880 41.03519444 28.82001389
3 ED0018 41.26675 26.687669399999997
3 IB9048 40.98021667 28.833175
3 IS0034 41.10741944 28.80134167
3 IS0063 40.97868889 28.72448889
3 IS0280 41.1085556 28.874861100000004
我想计算具有相同“SC”的位置之间的距离,并添加到新列中。
我计划
distance between WED0002-WED0016 to column Neig1
distance between WED0002-WED0030 to column Neig2
distance between WED0002-WED0134 to column Neig3
distance between WED0016-WED0030 to column Neig1
distance between WED0016-WED0134 to column Neig2
地理距离计算代码:
def global_distance(location1, location2):
lat1, lon1 = location1
lat2, lon2 = location2
radius = 6371 # radius of the Earth
dlat = math.radians(lat2-lat1)
dlon = math.radians(lon2-lon1)
a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) \
* math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
d = radius * c
return d
从评论中你可以看到我是如何建立这一点的
itertools.combinations
在SCexplode()
将这个对列表转换为行merge()
中使用geopy.distance
计算距离从您的示例数据中,我看不到与您声明的所需列的映射。一切都很简单,现在你有了所有有效的组合和它们之间的距离
输出
补充更新
需要处理边缘情况,SC只有一个网络\u CELLID。为自身生成一个合成的
tuple
相关问题 更多 >
编程相关推荐