【问题标题】:Select points with constant distance along a list, python沿着列表选择具有恒定距离的点,python
【发布时间】:2021-06-10 12:04:32
【问题描述】:

我是地理空间 python 库和距离计算的新手,我想避免可能非常昂贵的 for 循环。

我有纬度和经度列表,我需要沿轨迹顺序创建另一个固定 dist=5 的点列表。

list_x = []
list_y = []
r_val = 5
long[0] = long_start
lat[0] = lat_start
for i,j in zip(range(len(long)), range(len(lat))):
    for i,j in zip(range(len(long)), range(len(lat))):
        long_cent = long[i]
        lat_cent = lat[j]
        if ( (np.sqrt((long[i+1]-long_cent)**2 + (lat[j+1]- 
        lat_cent)**2)>= np.ceil(r_val)) ):
           list_x.append(long[i])
           list_y.append(lat[j])

I need to update the i,j of the first for loop and compute the 
distances of the second for loop starting form the update (i,j)

我需要一个新的列表 d_long, d_lat 包含 dist=5 的点的纬度和经度 如下

d_long = [long_a,long_d,long_g,long_i] 
d_lat = [lat_a,lat_d,lat_g,lat_i]

在哪里

(long_d,lat_d) is the first element that dist=5 from (long_a,lat_a),
(long_g,lat_g) is the first element that dist=5 from (long_d,lat_d),
(long_i,lat_i) the following element that dist=5 from (long_g,lat_g)

您能否建议任何有效的解决方案,使用 pandas、geopandas 或除 python 循环之外的任何其他灵魂?

【问题讨论】:

  • 不清楚您要的是什么。请提供一个示例,并展示一个具有具体最小输入和预期输出的参考实现。

标签: python pandas numpy geospatial geopandas


【解决方案1】:

你可以试试这个,

for x in range(1,len(long),3#this is the gap):
  d_long.append(long[x])

【讨论】:

  • 谢谢,但纬度没有相同的差距。我需要计算欧几里得距离,这样纬度和经度就可以给我所需的距离。
【解决方案2】:

已解决

在链接中的“指定距离分割”中有说明 How to get equally spaced points on a line in Shapely

在这篇文章中,Parsing a WKT-file 如何将等间距坐标转换为列表

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 2013-10-18
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多