2 years ago
#9541
Adrian Zalewski
Problem with getting correct bus lines from GTFS using php, csv and mysql
I need to get transport data for my mobile app. Especially i would like to get Stop list with bus lines that stops on each bus stop.
I downloaded data from this link http://gtfs.ztp.krakow.pl/
- Data for buses: GTFS_KRK_A.zip
- Data for trams: GTFS_KRK_T.zip
Using PHP simple code I unzipped it, read .csv values from .txt files, add another column with changed varchar id to int id values using explode function, then save those files as .csv again to load it into transaction using mysql (that helps me introduce relations using indexes).
As I know the only possible way to get it is to connect 4 tables like stops with stop_times then, stop_times with trips and in the end trips with routes to get relation bus stop <--> route.
My SQL query is:
SELECT DISTINCT r.route_short_name
FROM google_transit_routes r
JOIN google_transit_trips t ON t.route_id_int = r.route_id_int
JOIN google_transit_stop_times st ON t.trip_id_int = st.trip_id_int
JOIN google_transit_stops s ON s.stop_id_int = st.stop_id_int
WHERE s.stop_name LIKE "Bieńczycka"
ORDER BY r.route_short_name ASC
Which returns:
- 103
- 125
- 127
- 129
- 664
When I check this bus stop online (which I believe is correct) it shows other lines that courses on this bus stop:
https://www.mapakrakow.pl/?ir=2&przystanek=Bie%C5%84czycka&lang=pl
103 and 644 are OK, but 125, 127, 129 shouldn't be in the return of my query.
Lines: 1, 5, 9, 14, 52, 64 are for trams which I didn't load yet - so it's good that query didn't return them.
Do you guys have any idea how to solve this problem?
php
mysql
csv
gtfs
0 Answers
Your Answer