Create routable network from GTFS files
This page describes how the model builds a routable public transport network from the GTFS source files. The configuration is in cfg/main/SourceData/GTFS.dms, which includes LoadFeeds.dms, RelevantSelection.dms and PT_Hubs.dms from cfg/main/SourceData/GTFS. In the configuration tree the container is /SourceData/Infrastructure/GTFS.
GTFS data model
GTFS (General Transit Feed Specification) is a widely used open standard for public transport timetables. The model reads the following GTFS files:
| File | Contents |
|---|---|
agency.txt | The agencies (operators) whose services the feed includes |
calendar.txt | Weekly service schedules with start and end dates |
calendar_dates.txt | Exceptions to the calendar, such as added or removed service days |
routes.txt | Routes; a route groups the trips that passengers see as one service |
shapes.txt | The geographic paths of the vehicles |
stop_times.txt | Scheduled arrival and departure times at each stop for each trip |
stops.txt | Stops with their coordinates, names and identifiers |
trips.txt | Trips, each of one route and with the service days on which it runs |
For the Netherlands, the national access point for public transport data is the NDOV Loket. The model uses the national GTFS feed of OVapi, a community service; The GTFS feed describes how to get a feed. The model reads one feed: the folder of GTFS_file_date, with the eight files that LoadFeeds/File_Structure lists.
Step 1: loading GTFS text files into an MMD cache
GTFS files are plain text csv files. Reading them again in every analysis would be slow, so the model first converts them once to a GeoDMS MMD cache with LoadFeeds/Write, one table per file. LoadFeeds/Load reads each csv from %NetworkModel_Dir%/Infrastructuur/GTFS/<GTFS_file_date>/ with the template LoadFeeds/LoadCSVThroughGDAL_T. All later steps read the cache through LoadFeeds/Read:
'%LocalDataProjDir%/GTFS/' + GTFS_file_date + '.mmd'
The parameter GTFS_file_date (for example '20231003') is the download date of the feed. It follows from the preset of AnalysisMoment; see The GTFS feed.
Step 2: date selection and service filtering
The model analyses one calendar date D, ModelParameters/Impl/Analysis_date. It is ModelParameters/AnalysisDay when that is set. Otherwise it follows from AnalysisMoment, like the feed: the second Tuesday of October of the reference year, for example '20251014' for Y2025 (#125). The feed is always that of AnalysisMoment, so it must cover a day set in AnalysisDay (ChecksBeforeRunning/Check_GTFS). All times are seconds since 00:00 of D, on one time axis of 48 hours (Time). The axis does not wrap at midnight: a time after midnight is 86,400 or more, and a period that crosses midnight, such as 23:00 to 01:00, is one interval. Departure moments always lie on D itself.
Three service days
The model builds the network from three service days (LoadFeeds/ServiceDays):
| service day | which trips | position on the axis |
|---|---|---|
| D−1 | the part after midnight: stop times of 24:00 or later | GTFS time − 24 h |
| D | all trips, including their times of 24:00 or later | GTFS time |
| D+1 | whole trips that start before the end of the time window | GTFS time + 24 h |
In a GTFS feed a service day continues after midnight with times of 24:00 and later. On a Tuesday in the feed of 16 March 2026, for example, 41,700 of the 2.31 million departures are after midnight (35,500 between 24:00 and 25:00), while the day itself has only 33 departures before 01:00. Public transport between midnight and about 02:00 therefore comes almost entirely from D−1.
The time window runs from Impl/PT_FirstDepartureMoment, the first departure moment, to Impl/PT_LastArrivalMoment. That is the last departure moment plus MaxPTTime, plus Advanced/MaxWaitingTimeAtOrigin when the waiting time at home does not count in the travel time (Advanced/IncludeWaitingAtHomeInTravelTime FALSE, the default). D+1 therefore only adds links when the window crosses midnight. With departures at 23:00 to 23:45 on 1 October 2024 it adds 117 links.
The dates of D−1 and D+1 follow from a day number, not from arithmetic on the digits of yyyymmdd. On the first day of a month, that arithmetic would give a date that does not exist. Templates/DayNr_T converts yyyymmdd to a day number (days since 1 January 1970), and Templates/CivilDate_T converts it back.
Checks on the date
When the model builds the network, it computes two checks on the chosen date (the ExplicitSuppliers of RelevantSelection/ScheduledLinks). Each check that fails stops the run with a failed integrity check:
Check_ServiceDaysComplete: every service day the window needs has at leastAdvanced/MinServiceDayTripShare(0.95) of the trips of the busiest day of the same weekday in the feed. The window always needs D, D−1 when it starts beforeImpl/PrevServiceDayTailEnd(06:00), and D+1 when it ends after midnight. A feed is complete for only a few weeks. In the feed of 16 March 2026, a Tuesday three weeks later has 6% fewer trips than the first Tuesday, a Tuesday four weeks later 9% fewer, and from July less than half. A public holiday runs a Sunday service, so it fails as well.ServiceDays/Reportlists the numbers per day.Check_NoDSTChange: D, and D+1 when the window crosses midnight, is not the last Sunday of March or October. GTFS counts the times of a service day from noon minus 12 hours, which on those days is not midnight.
Whether the weekday of D matches CongestionSpeed_DaySelection, the day of the TomTom car speeds, matters only for the direct car trip. ChecksBeforeRunning/Check_CarDay tests it before the run when the variant has the car (ServiceDays/WeekdayMatchesCongestionDay). The default is 'tuesday'; 'Weekday', 'Weekend' and 'Week' accept any day of that kind, but not for the time-dependent car trip (see Private transport).
Which services run
The unit Services adds up the exceptions of calendar_dates.txt per service identifier and day, in Today_exc, Yesterday_exc and Tomorrow_exc: the sum of exception_type on that date. An exception_type of 1 means that the service is added on that date, 2 that it is removed. A trip runs on a day when this sum is 1. The model uses only calendar_dates.txt, not the weekly patterns of calendar.txt; the OVapi feeds put every service day in calendar_dates.txt.
Step 3: constructing RawStops and the filtered Stops set
The model first loads all stops of stops.txt into RawStops. There LatLongWgs842RD converts their WGS84 coordinates (stop_lat, stop_lon) to Dutch Rijksdriehoek coordinates (rdc).
A stop with a latitude or longitude of 0 in the feed gets the point of its parent_station (IsWithoutPoint, Parent_rel), or keeps its own point when the parent has none. Otherwise all such stops would lie at one point, form one stop cluster and allow transfers between them at a distance of 0 m. In the feed of 25 September 2026 these are 187 stops, 45 of them with stop times. They are German platforms of the ICE from Amsterdam to Berlin and Hamburg and of DB trains near Münster, Dortmund and Lünen, each with a parent that has a point.
The attribute StopUsed then marks a stop as used when at least one stop time in RawStopTimes refers to it on one of the three service days:
StopUsed := any(RawStopTimes/SelToday, RawStopTimes/RawStop_rel)
|| any(RawStopTimes/SelYesterday, RawStopTimes/RawStop_rel)
|| any(RawStopTimes/SelTomorrow, RawStopTimes/RawStop_rel)
The public transport nodes (PT_Hubs) cluster only the stops with a departure on D, so a stop used only by a night trip of D−1 does not join two clusters.
The unit Stops in RelevantSelection selects the stops of RawStops whose StopUsed is true. Each stop gets the mode that serves it most often over all StopTimes (modus(StopTimes/Mode_rel, StopTimes/Stop_rel)). GTFS/PublicTransportNet/Stops is the same set of stops, with the attributes that the public transport model needs later.
Stop clusters
Find_StopClusters finds the adjacent platforms of one station and the stops on both sides of a street: with join_near_values it finds all pairs of stops within DistanceStopClusters (100 m) of each other. The model uses its c_Stop_Stop_rel to drop the rides that start and end within one cluster (IsStartEndWithinSameStopCluster in OD_extra_attributen.dms).
NS station mapping
Find_Trainstations_Clusters links each stop to the known train stations within DistanceTrainStationsSelection (350 m). Through the station code it then finds the matching NS_Stations_rel in the NS fare data. A rail stop without a station within that distance is matched on its name instead (Trainstation_byname_rel): rail platforms carry the name of their station, bus stops do not. In the feed of 25 September 2026, for example, the platforms of Vught lie about 600 m south of the station point. The name match gives the rides that board or alight there an NS station, and so an NS price. The flag IsNSICStation comes from the distance match only. The NS price and the NS through fare need these attributes.
OV-fiets stations
Find_OVFiets_Stops links the stops to the OV-fiets locations of the analysis moment (OV_Fiets_Stations, from Impl/OVFiets_File) within DistanceOVFietsStops (200 m). This gives the flag IsOVFietsStation. The OV-fiets post-transport type (OVF_Stops2Dest_Cycling) starts only at stops with this flag.
Step 4: constructing ScheduledLinks
RawStopTimes adds to each stop time the service-day flags of its trip, and its NextStopId: the stop time of the same trip with the next stop sequence number. Each stop time except the last of its trip thus forms one link, from stop N to stop N+1.
The template DayLinks_T builds the links per service day, in RawStopTimes/Yesterday/Links, RawStopTimes/Today/Links and RawStopTimes/Tomorrow/Links, with the times shifted by −24, 0 and +24 hours. The selection of each day (SelYesterdayNet, SelTodayNet, SelTomorrowNet) leaves out the flex trips that LoadFeeds/FlexOptions thins out on that day. The length of a link comes from shape_dist_traveled when that is more than Advanced/MinShapeDistTraveled (100 m), and is otherwise the Euclidean length of the straight line between its two stops.
The ScheduledLinks unit in RelevantSelection is the union of the links of the three service days. Each link has:
FromStop_relandToStop_rel: references into the filteredStopsset.fromTime_relandtoTime_rel: departure and arrival times as time step indices.Duration: travel time in seconds, the arrival minus the departure. A link that crosses midnight needs no special rule, because the time axis runs on past 24:00. Only a GTFS time of 48:00 or later, past the end of the axis, wraps to its start (Templates/GTFS_getTimes_T); for such an arrivalDurationadds the length of the axis (#Time).Length: route distance in kilometres.Mode_rel,Route_rel,Agency_rel,Trip_rel: references to the relevant GTFS entities.FromPickupAllowed,FromDropOffAllowed,ToPickupAllowedandToDropOffAllowed: whether the GTFS (pickup_type,drop_off_type) allows boarding and alighting at the start and end of the link.c_FromTime_Stop_relandc_ToTime_Stop_rel: the combined keys ofc_Time_Stopsthat the whole public transport model uses.
Here the model also computes uq_TimeStop: the unique departure and arrival events (time and stop) of all ScheduledLinks, also called the scheduled space-time events (SSTE). The unique stop locations of the links form SL_Places. It is the domain Places of the GTFS container, and together with the origins and destinations it forms Places of PublicTransport_Prep.
Step 5: constructing WaitingAtStop links
The scheduled links alone do not yet form a routable network. A traveller in a train at an intermediate stop must wait until the train departs again, and no scheduled link represents this waiting time. To make the network routable, the model adds a waiting-at-stop link wherever a vehicle stands still: from the arrival to the departure of the same stop time.
GTFS/GetWaitingAtStop does this with the template CreateWaitingAtStopSet_T, in four steps:
doubledLinksdoubles all scheduled links into their departures and arrivals. A link departs at its own stop time (StopTime_rel) and arrives at the next stop time of its trip (NextStopId), so each event is a pair of a stop time and a time (c_StopTime_Time);IsArrivaltells an arrival from a departure.WaitingAtStop, the unique pairs in the order of stop time and time, has one moment per stop time and time. On each service day, a stop time where the vehicle arrives and departs in the same minute has one moment, and a stop time with a dwell has two: its arrival and its departure.- For each moment,
NextMomentgives the departure of its stop time when the moment is the arrival:add_or_null(id(.), 1)when the next moment has the same stop time, this moment is an arrival and the next one a departure. The departure on one service day and the arrival on the next are thus never linked. - A waiting link runs from each moment to its
NextMoment, with the time between them as itsDuration, computed as for a scheduled link. A moment without aNextMomentgets no waiting link: its row has noDuration, andPTnet_prep/IsRideLinkleaves it out ofSet_RandSet_L.
A moment is keyed by its stop time, not by its trip alone. Over a scheduled link of 0 seconds a trip is at two stops at the same time; with one moment per trip and time, its moments at the two stops would merge into one, and the dwell at one of the stops would lose its waiting link (#172).
Each event takes the stop of its own scheduled link (FromStop_rel or ToStop_rel), not a stop found by its point. Several stops can share one point: in the feed of 25 September 2026, 810 of the 49,947 stops in use. A dwell must join the nodes of its own stop, so that a ride can continue through that stop in the same vehicle.
Waiting links have Length = 0, Mode_rel = Waiting and no Agency_rel, but they keep the Route_rel of their trip. Both fare groups include them, so that a ride can continue past a stop where the vehicle stands still: Set_L takes the waiting links at NS stations, and Set_R the waiting links of the trips of regional agencies, which it recognises by the agency of their route (PTnet_prep/IsRegionalLink).
Step 6: the complete PublicTransportNet
GTFS/PublicTransportNet is the union of RelevantSelection/ScheduledLinks and GetWaitingAtStop/WaitingAtStop. This is the full routable network. Every link has a LinkType_rel (Scheduled or Waiting_at_Stop) from Classifications/LinkTypes.
For the NS price, the union also gets these attributes:
NS_StartPoint_relandNS_EndPoint_rel: the NS stations of the from-stop and the to-stop, throughStops/NS_Stations_rel.c_NS_start_end_rel: the combined key of the station pair, with which the model looks up NS prices and through fares inTariffUnitsMatrix(see Public transport fares).
This network is the input of Get_Windowed_Agency_Set_T in PublicTransport_Prep. It filters the links on the time window and the agency, which gives the subsets Set_R and Set_L for the OD matrix calculations of the rides. See the Script reference for the details of these steps.
Routes and TimeInvariantTypes
The unit Routes in RelevantSelection holds the routes of the GTFS routes.txt, and also a row for each element of Classifications/TimeInvariantTypes. The pre- and post-transport types (walking, cycling) are thus routes in the same domain as the scheduled public transport routes. This makes it simpler to look up attributes by mode and route throughout the model.