如何根据两个坐标之间的距离附加列表?

How to append a list based on the distance between two coordinates?

我正在尝试根据两个 lat/lon 坐标之间的距离附加一个数字列表。如果我有纬度和经度列表,以及点的压缩数组及其各自的纬度和经度,我该如何编写一个循环来附加两个坐标之间的距离小于 500 的点?我尝试了下面的方法,但不断出错。有什么建议吗?

import geopy.distance

latH = [25.5, 29.0, 27.2, 26.0, 30.1, 25.7, 26.3, 35.5] 
lonH = [-84.3, -85.0, -85.6, -90.3, -89.0, -89.7, -90.5, -86.2]

rain = [([29816.0, 24387, 33155.0, 32062.0, 31251.0],26.1915, -80.4492), ([30954.0, 31251.0, 32366.0, 32062.0] 26.1297, -81.7625)]
rain2 = []
for j in range(len(rain)):
    appendres = []
    for k in range(len(rain[j][0]):
        for i in range(len(latH)):
            if geopy.distance.distance((rain[j][1],rain[j][2]),(latH[i],lonH[i])).km <= 500.0:
                appendres.append(rain[k])
    rain2.append(appendres)

这适合你吗?

from geopy.distance import distance

latH = [25.5, 29.0, 27.2, 26.0, 30.1, 25.7, 26.3, 35.5] 
lonH = [-84.3, -85.0, -85.6, -90.3, -89.0, -89.7, -90.5, -86.2]

rain = [([29816.0, 24387, 33155.0, 32062.0, 31251.0], 26.1915, -80.4492), ([30954.0, 31251.0, 32366.0, 32062.0], 26.1297, -81.7625)]
rain2 = []

#   Since all your arrays are the same length...
for lat, lon in zip(latH, lonH):
    arr = []
    for data, lat_2, lon_2 in rain:
        if distance((lat, lon), (lat_2, lon_2)).km < 500:
            arr.append(data)
    rain2.append(arr)

print(rain2)
[[[29816.0, 24387, 33155.0, 32062.0, 31251.0], [30954.0, 31251.0, 32366.0, 32062.0]], [[30954.0, 31251.0, 32366.0, 32062.0]], [[30954.0, 31251.0, 32366.0, 32062.0]], [], [], [], [], []]

我编写的代码在行为上与您的类似,没有所有语法问题,而且对我来说意图更清晰。但是由于我们无法启动您的代码并且您没有提供所需的输出...我不能确定。