Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:43:06+00:00 2026-06-15T03:43:06+00:00

I’m working with some GTFS data and would like to be able to create

  • 0

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 data.

Trips.txt comes in a format like this:

route_id,service_id,trip_id,trip_headsign,direction_id,block_id,shape_id
1,A20120610WKD,A20120610WKD_000800_1..S03R,SOUTH FERRY,1,,1..S03R
1,A20120610WKD,A20120610WKD_002700_1..S03R,SOUTH FERRY,1,,1..S03R
1,A20120610WKD,A20120610WKD_004700_1..S03R,SOUTH FERRY,1,,1..S03R
1,A20120610WKD,A20120610WKD_006700_1..S03R,SOUTH FERRY,1,,1..S03R
1,A20120610WKD,A20120610WKD_008700_1..S03R,SOUTH FERRY,1,,1..S03R

I tried reading in the matching shape using the shape_id and then looking for stops with matching latitudes and longitudes but that doesn’t seem to work reliably. Does anybody know how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:43:08+00:00Added an answer on June 15, 2026 at 3:43 am

    As you’ve noticed, there isn’t a direct relationship between routes and stops in GTFS. Instead, stops are associated with trips, where each trip represents a single “run” of a vehicle along a particular route. This reflects the fact a route does not necessarily serve every one of its stops at all times—on weekends it might skip stops outside a high school, for instance.

    So getting a list of every stop served by a route involves combining several models:

    • routes.txt gives you the route ID for the route you’re interested in.
    • trips.txt gives you a set of trip IDs for that route.
    • stop_times.txt gives you a set of stop IDs for the stops served on each of these trips.
    • stops.txt gives you information about each of these stops.

    Assuming you’re using an SQL database to store your GTFS data, you might use a query like this (once you’ve obtained the route ID):

    SELECT stop_id, stop_name FROM stops WHERE stop_id IN (
      SELECT DISTINCT stop_id FROM stop_times WHERE trip_id IN (
        SELECT trip_id FROM trips WHERE route_id = <route_id>));
    

    Remember, though, this will output a record for every stop that is ever served by the route. If you’re generating schedule information for a rider you’ll probably want to limit the query to only trips running today and only stop times with departures in, say, the next thirty minutes.


    Update: I wrote the above SQL query the way I did as I felt it most simply illustrated the relationship between the GTFS models, but btse is correct (in his answer below) that a query like this would never actually be used in production. It’s too slow. You would instead use table joins and indices to keep query times reasonable.

    Here is an equivalent query, written in a way more suited to being copied and pasted into a real application:

    SELECT DISTINCT stops.stop_id, stops.stop_name
      FROM trips
      INNER JOIN stop_times ON stop_times.trip_id = trips.trip_id
      INNER JOIN stops ON stops.stop_id = stop_times.stop_id
      WHERE route_id = <route_id>;
    

    Typically you would also create an index for each column used in a JOIN or WHERE clause, which in this case would mean:

    CREATE INDEX stop_times_trip_id_index ON stop_times(trip_id);
    
    CREATE INDEX trips_route_id_index ON trips(route_id);
    

    (Note that RDBMSes normally index each table by its primary key automatically, so there is no need to explicitly create an index on stops.stop_id.)

    Many further optimizations are possible, depending on the specific DBMS in use and your willingness to sacrifice disk space for performance. But these commands will yield good performance on virtually any RDBMS without needlessly sacrificing clarity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to run a str_replace or preg_replace which looks for certain words
I would like to count the length of a string with PHP. The string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.