GTFS spec for reference: https://developers.google.com/transit/gtfs/reference/

I'm trying to create a program that counts the number of buses, trams, rails etc that pass through a certain stop during a day, for a certain route, and do a split-count for those that are end of lines.

My algorithm is as follows:

Given a route R
Given a day D

foreach R.trips as trip
    if trip.calendar_dates != D
         // skip all dates that we are not interested in

    endOfLines = 0
    notEndOfLines = 0

    foreach trip.stopTimes as stopTime
        // get all stop times of this trip, ordered by stop_sequence
        stopTimes = stopTime.trip.stopTimes.orderBy(stop_sequence)

        if stopTime.isFirstIn(stopTimes) or stopTime.isLastIn(stopTimes)

    results[route.route_type][end] = endOfLines
    results[route.route_type][notEnd] = notEndOfLines    

Explanation of what I'm trying to do:

  1. Take all the trips of the given route. Use calendar_dates to link the trips to the specific day and remove the trips that are not in our day of interest.

  2. Loop all the trips and take their stoptimes. Then, determine if this stop time is the first or last in the trip. If it is, then we count it as an end of line, otherwise we count it as a simple stop.

Since the GTFS spec is somehow vague about how the tables should be used, I'm trying to figure if this logic is correct. Can someone validate and point out if I have any mistakes in my logic?

closed as off-topic by Ian Turton Apr 22 at 19:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Might be better asked on code review – Ian Turton Apr 22 at 19:30
  • Saying "pass through" makes it sound like the buses travel past - but don't actually stop - at a particular stop. If in fact you're searching for the ones that don't stop, perhaps that would make this more relevant to GIS if it requires a spatial search. – Kirk Kuykendall Apr 22 at 22:51