pflaenz.li/pflaenzli/pflaenzli/utils/distance.py
2023-04-05 18:19:06 +02:00

17 lines
439 B
Python

from geopy.distance import distance
import os
from pandas import read_pickle
path = os.path.dirname(os.path.abspath(__file__))
df = read_pickle(os.path.join(path, 'plz.pkl'))
def calculate_distance(zip_1, zip_2):
zip_1_coords = tuple(df[df.index == zip_1].values)
zip_2_coords = tuple(df[df.index == zip_2].values)
dist = round(distance((zip_1_coords), (zip_2_coords)).kilometers)
return None if dist > 400 else dist