more info on routes to determine direction from stop_ids

Skip to first unread message

Beck L

Nov 10, 2021, 10:09:28 AM11/10/21
to MBTA Developers
How do I access the order of specific stops on a route? I am trying to determine the direction of a route given a trip's origin and destination stop_id. Thanks.

Just a nudge in the right direction would be appreciated 

Developer at MBTA

Nov 18, 2021, 3:27:28 PM11/18/21
to MBTA Developers
Hi Beck,

The resource best suited to this problem is RoutePattern, and its representative_trip relationship. For example, if you were using the endpoint /route_patterns, you would include the representative_trip relationship with a list of the representative_trip's stop IDs, i.e. /route_patterns?include=representative_trip.stops (the order of stops in a Trip is the same order in which they occur along that trip). Then you would go through these RoutePatterns, associate each with its representative_trip, find which ones contain the stop_ids you're looking for in the expected order, and look at the direction_id.

One thing to watch out for is that it's theoretically possible for a given origin and destination stop_id to appear in the same order in RoutePatterns with two different directions. In this case, your code should probably raise an error, as the direction of the trip cannot be determined from just two stops.

Reply all
Reply to author
0 new messages