Lewati ke isi

Routes, stops, and trips


Routes are at the core of fixed route transit operations as they describe the geographic reach of a transit network. In GTFS, defining routes is the first step to describing the operations of a transit agency.

The first step is to add the agency information as shown in the file agency.txt below. This file contains high level information about the agency.


CT,Calgary Transit,http://www.calgarytransit.com,America/Edmonton,,403-262-1000

Calgary Transit operates LRT, BRT, regular bus service, paratransit, and on-demand transit in Calgary, AB. In this example, two routes are defined, the first is a bus and the second is an LRT. Using the file routes.txt, each route is assigned a unique ID, and a short name as well as a long name for human readability.


CT,303-20670,303,MAX Orange Brentwood/Saddletowne,3,www.calgarytransit.com/content/transit/en/home/rider-information/max.html,#ff8000,#ffffff
CT,202-20666,202,Blue Line - Saddletowne/69 Street CTrain,0,www.calgarytransit.com/content/transit/en/home/rider-information/lrt-and-bus-station-maps.html,#ff0000,#ffffff

The fifth field (route_type) is used to differentiate the types of routes:

  • The first is a bus, hence route_type=3
  • The second is an LRT, hence route_type=0
  • A complete list of values for route_type can be found here

The remaining fields contain additional information such as a URL specific to the route as well as agency-specific colors to represent the service on a map.


In GTFS, stops and stations are described using the file stops.txt, below, a bus stop is defined in the first record and an LRT station is defined in the second record.


8157,8157,44th Avenue NE (SB),51.091106,-113.958565,0
6810,6810,NB Marlborough CTrain Station,51.058990,-113.981582,0
  • stop_id is a unique identifier
  • stop_code and stop_name typically contain rider-facing information
  • The exact location is provided using coordinates (stop_lat and stop_lon)
  • The sixth field (location_type) is used to differentiate stops from stations
  • The first record corresponds to a bus stop, hence location_type=0
  • The second record corresponds to station, hence location_type=1
  • A complete list of values for location_typecan be found here


After describing the agency’s routes, it is now possible to describe the trips that are served by each route.

First, the span of service needs to be defined using calendar.txt.



Here, a service that runs on Saturdays and Sundays only is being described, so the fields for those days are populated with 1, and the fields for the remaining days are populated with zero. This service runs from June 23 2022 until September 3 2022 as shown under the fields start_date and end_date.

In this example, the file trips.txt describes 3 weekend trips that are served by the MAX Orange route that was described above.


303-20670,weekend_service,60270564,"MAX ORANGE SADDLETOWNE",0,3030026
303-20670,weekend_service,60270565,"MAX ORANGE BRENTWOOD",1,3030027
303-20670,weekend_service,60270566,"MAX ORANGE BRENTWOOD",1,3030027
  • The route_id from routes.txt that corresponds to MAX Orange is listed
  • The service_id from calendar.txt that corresponds to weekends is listed
  • Each records contains a unique ID for each trip The headsign text is provided, which is what is typically displayed on signs inside and outside the the bus
  • The field direction_id allows for a distinction between trips of the same route going in different directions. For example, distinguishing between inbound trips and outbound trips - or southbound trips and northbound trips.
    • In this case, trips towards Saddletowne have a direction_id=0 and trips towards Brentwood have a direction_id=1. The values in direction_id have no inherent meaning, they are only used to assign one direction of travel versus another
  • The shape_id from shapes.txt that corresponds to the MAX Orange route towards Saddletowne is listed for the first record and the one for MAX Orange route towards Brentwood is listed for the second and third records

The shape_id=3030026 corresponds to the MAX Orange towards Saddletowne. The file below includes information on the points that outline the route as well as the distance between those points. With this information, it is possible to plot the route on a map for trip planning or analytics purposes.



Service exceptions

It is possible to define exceptions to the service such as added service days (special days) or removed service days (such as no service on holidays).

For example, if there is no scheduled service on Sunday July 17, 2022 - then that date can be removed from weekend_service in calendar.txt by breaking the service in two:

Service Start End
weekend_service1 20220623 20220716
weekend_service2 20220718 20220903

However, this complicates the file since service_id is broken in two and this break will cascade to trips.txt. Instead, this can be done in an easier way using calendar_dates.txt as shown below:


  • The service_id weekend_service is listed
  • The date of the removed or added service is listed under date (July 17 2022)
  • The field exception_type is set to 2, which means that service is removed for this day

Example source