【问题标题】:Geopandas pair of points (geometry) to linestringGeopandas 点对(几何)到线串
【发布时间】:2021-08-28 22:31:20
【问题描述】:

如您所见,我完全是新手。我想从两个 POINT 几何创建一个 LINESTRING,然后确定中间点。因此,从我原来的带有 x 和 y 列的 pandas 数据框中,我创建了以下 geopandas 数据框:

zone_short_edges = 
 id  vertex_id                    from \
1  A1                2  POINT (119.79008 28.35047)   
3  A1                4  POINT (122.85067 44.85106)   
5  A2                1  POINT (138.79141 26.48802)   
7  A2                3  POINT (141.73386 44.89716)   

                     to    seg_length  
1  POINT (122.85067 28.08433)    3.072140  
3  POINT (119.92314 44.71798)    2.930553  
5  POINT (141.92247 26.26168)    3.139230  
7  POINT (138.79141 44.89716)    2.942450 

其中fr_pointto_point 是dtype = geomtry

现在,我面临两个选择:

  1. 为每一对创建一个 LINESTRING,然后找到该线串的中点。
  2. 找到中点(我真正想要找到将段划分为相等长度的 N 段的所有 POINT 的可能性)。

我试过这样做:

geometry = [xy for xy in zip(zone_short_edges.fr_point, zone_short_edges.to_point)]
LineString([geometry]).wkt

我也尝试了这里提供的解决方案:https://stackoverflow.com/a/66494934/5363686

但是,两者都失败了。

有什么想法可以让我朝着正确的方向前进,或者我真的需要转到我的原始数据框吗?

【问题讨论】:

    标签: python pandas geopandas


    【解决方案1】:

    如果您的目标是获得中点,那么您可以使用一些数学来代替。我相信它还会为您节省一些运行时间...我有一段时间没有接触过 python-gis 但也许这会对您有所帮助。
    伪代码:

    # lat1,lat2,lon1,lon2 should be in radian
    Bx = cos(lat2) * cos(lon2-lon1);
    By = cos(lat2) * sin(lon2-lon1);
    
    latMid = atan2(sin(lat1) + sin(lat2), 
                 sqrt( (cos(lat1)+Bx)*(cos(lat1)+Bx) + By*By ) );
    lonMid = lon1 + atan2(By, cos(lat1) + Bx);
    

    您没有指定坐标系,因此计算可能是错误的,快速搜索应该会为您提供正确的解决方案。 此外,这种交流也可以帮助你 How to calculate the midpoint of several geolocations in python

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-31
      • 1970-01-01
      • 1970-01-01
      • 2019-10-08
      • 2021-06-21
      • 2020-07-22
      • 2018-12-06
      相关资源
      最近更新 更多