How can I list all the stops associated with a route using GTFS?

后端 未结 6 662
执笔经年
执笔经年 2020-12-23 22:49

I\'m working with some GTFS data and would like to be able to create a list of all stops associated served by a route. I don\'t really understand how to do with with GTFS da

6条回答
  •  不思量自难忘°
    2020-12-23 23:04

    I came across this post in my Google searches and I figured I would update it with a better answer in case anyone else stumbles upon it. The answer that Simon gave is 100% correct, however, the query he provided is quite slow for large GTFS feeds. Here is a query that does the same thing, but performs significantly faster.

    Just to give you some anecdotal evidence, for a GTFS feed of about 50mb, Simon's query took anywhere from 10-25 seconds to complete. The statement below takes consistently < 0.2 seconds.

    SELECT T3.stop_id, T3.stop_name 
    FROM trips AS T1
    JOIN
    stop_times AS T2
    ON T1.trip_id=T2.trip_id AND route_id = 
    JOIN stops AS T3
    ON T2.stop_id=T3.stop_id
    GROUP BY T3.stop_id, T3.stop_name
    

    UPDATE:

    I realized I didn't mention this before, but of course you will want to have indexes where each of the tables are being joined.

提交回复
热议问题