-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_stations.py
21 lines (15 loc) · 920 Bytes
/
update_stations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import pandas as pd
from geopy.distance import distance
from tqdm import tqdm
tqdm.pandas()
df = pd.read_csv('https://raw.githubusercontent.com/trainline-eu/stations/master/stations.csv', sep=';',
usecols=['name', 'latitude', 'longitude', 'country', 'trenitalia_rtvt_id'])
df = df.query('country == "IT" & trenitalia_rtvt_id.notnull() & latitude.notnull() & longitude.notnull()')
santa_lucia_coords = 45.441569, 12.320882
# filter out stations that are more than 110km away from Santa Lucia
df['distance'] = df.progress_apply(lambda row: distance(santa_lucia_coords, (row['latitude'], row['longitude'])).km,
axis=1)
df = df.query('distance < 110')
df = df[['name', 'latitude', 'longitude', 'trenitalia_rtvt_id']]
df.columns = ['long_name', 'latitude', 'longitude', 'code']
df.to_json('MuoVErsi/sources/data/trenitalia_stations.json', orient='records', indent=2)