Quick way to determine lines passing through stop/station?


Is there a quick and easy way to use the GTFS data to determine the line(s) that passes through the stop and/or stations for trains? I know you could do this by searching through all the separate data file, but I want something less resource intensive.



There is an API which can give this which is not yet published on Open Data. Can I ask what you’re trying to achieve by doing this?
Just a small caveat for this is that you will very likely get a lot more lines/services than you (or a customer) would reasonably expect, as there will almost always be services which show up at a stop (say) once a day or once a week which may seem a bit abnormal. e.g. the T2 stopping at Canterbury station, which is normally only serviced by the T3, or the T7 stopping at Central Station due to special events.


Ah. I thought that might happen. Some of my users were requesting it so they can easily see what line they are viewing when selecting their platform to view the departures at.


Have a play with the departures tool on the transportnsw.info website.

After you make a departures request for a stop, click the filters button and you will be presented with some lines/services which pass through that stop. Try it out for some random stops. There is further complexity involved in having different experiences for stop groups and stop points (I am assuming you understand the difference). At the moment, we are still working on the stop point scenario and the available routes list is definitely giving us results which a customer would not necessarily expect.


Without our API, you could do this calculation yourself using the GTFS data. Keep in mind that the results probably won’t change much… you wouldn’t need to do it each and every time a user required this data. You could simply build your own dataset periodically and then expose your own service for it. That way you could also set your own rules about things you may not want to show.


Generating a file that contained it once in a while would probably be the best way to go ahead. I’ll try implementing this tonight. Thanks


Good luck. Let us know if you encounter any “weird” data and have questions about it.


Spent the night writing some messy, yet functional, code to generate a JSON and CSV containing the stop_ids and the lines that stop at them (which I’ve attached). There, as expected earlier in the thread, are some unexpected results. If anyone is interested in the Java code just let me know.

stop_lines.zip (7.7 KB)