-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVIA.py
More file actions
57 lines (39 loc) · 1.54 KB
/
VIA.py
File metadata and controls
57 lines (39 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from ast import Index
from numpy.testing import break_cycles
import pandas as pd
import matplotlib.pyplot as plt
ROUTE_ID = ""
df_shapes = pd.read_csv('shapes.csv')
df_routes = pd.read_csv("routes.csv")
df_trips = pd.read_csv("trips.csv")
df_stoptimes = pd.read_csv("stop_times.csv")
df_stops = pd.read_csv("stops.csv")
print("Enter the number of the route to view.")
for i, (index, row) in enumerate(df_routes.iterrows()):
print(str(i) + ". " + row["route_long_name"] + " - " + row["route_id"])
num = int(input("Enter route number: "))
if 0 <= num < len(df_routes):
ROUTE_ID = df_routes["route_id"].iloc[num]
else:
raise ValueError("Invalid route number.")
route_long_name = df_routes[ df_routes["route_id"] == ROUTE_ID]["route_long_name"].iloc[0]
df_trips = df_trips[df_trips["route_id"] == ROUTE_ID]
shape_id = df_trips["shape_id"].iloc[0]
df_shapes = df_shapes[df_shapes["shape_id"] == shape_id]
lat = df_shapes["shape_pt_lat"]
lon = df_shapes["shape_pt_lon"]
plt.plot(lon, lat, label="Route: "+ROUTE_ID)
df_stoptimes = df_stoptimes[ df_stoptimes["trip_id"] == shape_id]
stop_ids = df_stoptimes["stop_id"]
for stop_id in stop_ids:
stops = df_stops[ df_stops["stop_id"] == stop_id]
_lat = stops["stop_lat"].iloc[0]
_lon = stops["stop_lon"].iloc[0]
_name = stops["stop_name"].iloc[0]
plt.plot(_lon, _lat, "o", color="black", )
plt.text(_lon, _lat, _name, fontsize=8, color="black")
plt.legend()
plt.title("VIA RAIL ROUTE " + str(ROUTE_ID) + ", " + route_long_name)
plt.xlabel("Longitude")
plt.ylabel("Latitude")
plt.show()