我有四张经纬度表
‘’shop_long = -123.223,-127.223,-123.223,-123.048
shop_lat = [49.1534, 55.1303, 49.1534, 53.2563]
cus_long = [-126.07325247944962, -126.07255765553835, -126.07485428820583,
-126.0733578858899, -126.07270416708549]
cus_lat = [51.29548801984406, 51.29486187466757, 51.29566033167437,
51.295612714656855]
distance = []
shop = (shop_long, shop_lat)
customer = (cus_long, cus_lat)
print(geodesic(shop, customer).miles)'''我想用顾客的经度和经度来计算顾客和商店之间的距离,并把它附加到距离列表中。请帮帮我。
发布于 2022-11-28 07:09:19
考虑利用zip
from geopy.distance import geodesic
def main() -> None:
shop_long = [-123.223, -127.223, -123.223, -123.048]
shop_lat = [49.1534, 55.1303, 49.1534, 53.2563]
shop_cords = [(lat, long) for lat, long in zip(shop_lat, shop_long)]
cus_long = [-126.07325247944962, -126.07255765553835, -126.07485428820583,
-126.0733578858899, -126.07270416708549]
cus_lat = [51.29548801984406, 51.29486187466757, 51.29566033167437,
51.295612714656855]
cus_cords = [(lat, long) for lat, long in zip(cus_lat, cus_long)]
cus_dists_to_shops = {
f'cus_{cus_index}_dists': [f'{geodesic(cus, shop).km:.2f}km' for shop in shop_cords]
for cus_index, cus in enumerate(cus_cords, start=1)
}
print(cus_dists_to_shops)
if __name__ == '__main__':
main()输出:
{
'cus_1_dists': ['313.23km', '433.62km', '313.23km', '300.35km'],
'cus_2_dists': ['313.15km', '433.69km', '313.15km', '300.37km'],
'cus_3_dists': ['313.32km', '433.58km', '313.32km', '300.41km'],
'cus_4_dists': ['313.25km', '433.60km', '313.25km', '300.35km']
}https://stackoverflow.com/questions/74596952
复制相似问题