沿列表选择具有恒定距离的点,python

问题描述

我是地理空间 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,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 循环以外的任何其他解决方案的有效解决方案?

解决方法

已解决

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

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

,

你可以试试这个,

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