import pandas as pd
import numpy as np
from geopy.distance import geodesic
from tqdm import tqdm # Import tqdm
import swifter # Import swifter
def calculate_azimuth(lat1, lon1, lat2, lon2):
"""计算从点1到点2的方位角"""
lon1, lat1, lon2, lat2 = map(np.radians, [lon1, lat1, lon2, lat2])
dlon = lon2 - lon1
x = np.sin(dlon) * np.cos(lat2)
y = np.cos(lat1) * np.sin(lat2) - np.sin(lat1) * np.cos(lat2) * np.cos(dlon)
initial_bearing = np.arctan2(x, y)
initial_bearing = np.degrees(initial_bearing)
compass_bearing = (initial_bearing + 360) % 360
return compass_bearing
def calculate_distance(row1, row2):
"""计算两个点之间的地理位置距离(千米)"""
return geodesic((row1['Latitude'], row1['Longitude']), (row2['Latitude'], row2['Longitude'])).kilometers
def is_neighbor(row1, row2, distance, azi1, azi2, alpha_s, alpha_n):
"""根据距离和夹角判断是否为邻区"""
if distance