我正在尝试创建线条的基本起点/终点地图。我的数据具有以下结构:
ID lon_origin lat_origin lon_destination lat_destination
0 -116.284 43.617 -116.304 43.608
1 -116.291 43.610 -116.304 43.608
关于如何连接出发地和目的地的任何想法?我曾尝试将它们压缩,但无法让geopandas一次识别两个几何列。
答案 0 :(得分:0)
如果只想计算距离,这是一种解决方案:
from geopy.distance import lonlat, distance
data = """
id lon_origin lat_origin lon_destination lat_destination
0 -116.284 43.617 -116.304 43.608
1 -116.291 43.610 -116.304 43.608
"""
df = pd.read_csv(pd.compat.StringIO(data), sep='\s+')
df['KM'] = df.apply(
(lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
lonlat(row['lon_destination'], row['lat_destination'])).km), axis=1)
print(df)
输出:
id lon_origin lat_origin lon_destination lat_destination KM
0 0 -116.284 43.617 -116.304 43.608 1.89910
1 1 -116.291 43.610 -116.304 43.608 1.07277
如果要使用Miles,只需更改指标:
df['MILES'] = df.apply(
(lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
lonlat(row['lon_destination'], row['lat_destination'])).miles), axis=1)
id lon_origin lat_origin lon_destination lat_destination MILES
0 0 -116.284 43.617 -116.304 43.608 1.180046
1 1 -116.291 43.610 -116.304 43.608 0.666588
答案 1 :(得分:0)
我放弃了drawgreatcircle函数,因为按照我使用的比例,它不会很大或不是圆形的。 plt.plot做了我想要做的: Code & Output