I\'m working with GTFS structure for the first time and am having trouble with the queries. I\'ve got the transit data into mysql tables, and am free to query them, but I f
simply joining data together, joining to stops
twice for start and end stop and joining to stop_times
twice for start and end stop_times,
the only thing i am unsure about is where direction_id
comes from.
try the below query.
At the very end of the query, you can specify start_s.stop_id
and end_s.stop_id
which represents the two stops you're querying data about.
SELECT t.trip_id,
start_s.stop_name as departure_stop,
start_st.departure_time,
direction_id as direction,
end_s.stop_name as arrival_stop,
end_st.arrival_time
FROM
trips t INNER JOIN calendar c ON t.service_id = c.service_id
INNER JOIN routes r ON t.route_id = r.route_id
INNER JOIN stop_times start_st ON t.trip_id = start_st.trip_id
INNER JOIN stops start_s ON start_st.stop_id = start_s.stop_id
INNER JOIN stop_times end_st ON t.trip_id = end_st.trip_id
INNER JOIN stops end_s ON end_st.stop_id = end_s.stop_id
WHERE c.monday = 1
AND direction_id = 1
AND start_st.departure_time > "00:00:00" AND start_st.departure_time < "23:59:59"
AND r.route_id = 1
AND start_s.stop_id = 42
AND end_s.stop_id = 1
I tried looking up GTFS structure example from this link and i couldn't find anything on direction_id
To specify stop names instead of AND start_s.stop_id = 42 AND end_s.stop_id = 1
just use AND start_s.stop_name = 'Garrison' AND end_s.stop_name = 'Grand Central'