def retrieve_neighbors(index_center, df, spatial_threshold, temporal_threshold):
neigborhood = []
center_point = df.loc[index_center]
# filter by time
min_time = center_point['date_time'] - timedelta(seconds=temporal_threshold)
max_time = center_point['date_time'] + timedelta(seconds=temporal_threshold)
df = df[(df['date_time'] >= min_time) & (df['date_time'] <= max_time)]
# filter by distance
for index, point in df.iterrows():
if index != index_center:
distance = great_circle(
(center_point['latitude'], center_point['longitude']),
(point['latitude'], point['longitude'])).meters
if distance <= spatial_threshold:
neigborhood.append(index)
return neigborhood
评论列表
文章目录