Geopandas连接点

问题描述 投票:0回答:2

我正在尝试创建线的基本原点/目标地图。我的数据有这样的结构:

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同时识别两个几何列。

python pandas gis geopandas
2个回答
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

如果您想使用里程,只需更改指标:

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

0
投票

我结束了放弃drawgreatcircle功能,因为它在我使用的规模上不会很大或是圆形的。 plt.plot做了我的追求:Code & Output

© www.soinside.com 2019 - 2024. All rights reserved.