Malaysia Transit + SG-JB Transit
Technical white paper · November 2026
Enhanced route lines from OpenStreetMap
How Malaysia Transit and SG-JB Transit draw every bus route along its roads and every train along its track: built ahead of time from OpenStreetMap with pfaedle and a track-following method of our own, in place of Google Directions.
1,337
route patterns drawn along roads and track, for 19 timetables in Malaysia, Singapore and southern Thailand
5.5 m
from Causeway Link's own route maps, on average: how closely pfaedle's lines follow them
20 min
to rebuild every line on our own server, with nothing to pay per line shown
Appendix D of the white paper Malaysia Transit and SG-JB TransitVersion 1.0 · 27 November 2026
At a glance

Enhanced route lines from OpenStreetMap

A route line is what the map draws for a route between its stops. Since 26 November 2026, Malaysia Transit and SG-JB Transit draw their Enhanced route lines from OpenStreetMap, the open map of the world, instead of Google Directions. Buses are matched to the roads with pfaedle, an open-source tool from the University of Freiburg made for exactly this job, and trains follow the railway track by a method of our own that also finds stations a timetable puts in the wrong place.

1,337
route patterns drawn: 1,210 bus patterns by pfaedle, 127 train patterns along the track
802
Singapore bus service directions, which LTA publishes with no lines at all
6–11 m
from the stops to the new lines, on average, across the eight BAS.MY timetables tested
23
KTM stations found off the railway or out of order in the timetable, reported back
In four points

Contents

1What a route line is
2Where the lines came from
3Why Google's lines had to go
4The options
5OpenStreetMap, the map underneath
6pfaedle, in brief
7How pfaedle matches a route
8Our build, step by step
9Trains, along the track
10Routes no timetable draws
11The trial
12What is built today
13Against Google's lines
14What the build found
15How the apps use the lines
16Rebuilding
17Licence and credit
18Limits and next steps
19Sources
Background

Why route lines needed a new source

Riders read a route from its line. Most of the timetables we show don't draw one that follows the roads, and the service that used to draw them for us came with terms our maps can't meet.

1What a route line is

A route line is the path the map draws for a bus or train route between its stops. Riders use it to see which roads a bus takes, where it turns and where to wait for it, and the apps draw each ride of a planned journey along it. Both products offer two styles, switched on the map under Route Style:

Basic

The stops joined by straight lines, or the operator's own line where its timetable has one. Always available, and honest about what the timetable says.

Enhanced

The route along the roads it really takes, and trains along their track. Labelled "✓ Enhanced along OpenStreetMap" where the line comes from this work.

Timetables in the GTFS format may carry each route's path (the optional shapes.txt file), but most of the ones we show don't carry one that follows the roads:

Prasarana's feeds (Rapid KL's buses and trains, the MRT feeders and Rapid Penang), BAS.MY's for Johor Bahru and Melaka (5 to 20 points per stop) and Rapid Kuantan's already have good lines of their own, and keep them. The server uses an Enhanced line where a timetable's own is too sparse to follow the roads: fewer than 1.5 points per stop, no line at all, or a KTM train.

2Where the lines came from

Until 26 November 2026, Enhanced lines came from Google Directions, in three ways:

3Why Google's lines had to go

Not allowed on our maps

Google's Service Specific Terms say Directions results "must not" be used "in conjunction with a non-Google map" (section 4.2). Our websites draw with Leaflet on an OpenStreetMap map, and the apps with MapLibre: neither is Google's.

Not allowed to keep

Only latitudes and longitudes may be cached, for up to 30 days (section 4.3), and the general terms forbid storing Google's content or making new content from it (section 3.2.3). Lines saved into timetables, or cached for good, did both.

Not the bus's roads

A directions service finds its own best way between each pair of stops: it doesn't know which roads the bus takes. Where a stop sat a little off the road, Google's line sometimes swerved onto another road to reach it.

A bill that grows

Every line asked for is a billed request (US$5.00 per 1,000 Directions calls after 10,000 free a month), and the risk was larger than the bill: breaking the terms lets Google suspend the account's Maps services, all at once.

4The options

On 26 November 2026 the first plan was to fall back to Basic lines everywhere, until we asked whether Enhanced lines could come from somewhere other than Google. These were weighed:

OptionHow it worksVerdict
Basic lines onlyThe stops joined up, or the operator's lineAllowed and free, but gives up the road-following lines riders had
pfaedleMatches whole timetables to OpenStreetMap's roads and railways ahead of timeChosen Made for exactly this, open source, offline, about a minute per timetable
MOTIS's route shapesThe journey planner can work out lines for trips without one from its own street routing (its route_shapes setting)Not yet running when the lines were needed, and it would tie the route views to the planner. The planner now draws its rides along pfaedle's lines instead
ValhallaAn open-source router with a bus profile, which can snap points to the roads when a line is asked forOne more service to run and call while riders wait, as Google was. Building lines ahead of time is simpler, and each can be checked before anyone sees it
Google DirectionsDirections through the stopsNot allowed on our maps or to keep (section 3)

We trialled pfaedle on the server first (section 11). Its first lines looked better than Google's had, and they became the new Enhanced the same day.

Method

How the lines are made

Buses and trains are drawn by two methods, on the same OpenStreetMap data, into the same kind of file. Both run ahead of time, so riders never wait on them.

5OpenStreetMap, the map underneath

OpenStreetMap is the free, editable map of the world, made by volunteers and published under the Open Database Licence. Besides drawing the base map of both products, it describes everything a route line needs:

WhatHow OpenStreetMap records itUsed for
Roadshighway=* ways, from motorways to service roads, with oneway and access tagsBus lines
Turn rulestype=restriction relations (no right turn, only straight on…)Bus lines
Railway trackrailway=rail ways, with service=siding, yard, crossover or spur for side trackTrain lines
Stops and stationsBus stops, platforms, stop positions and stations, with their namesPlacing stops; station positions

6pfaedle, in brief

pfaedle is a free, open-source tool that gives a GTFS timetable its route lines by matching every trip to OpenStreetMap. It comes from the Chair of Algorithms and Data Structures at the University of Freiburg in Germany (Professor Hannah Bast's group), where Patrick Brosi wrote it and still develops it. It first appeared in 2018, with the paper "Sparse Map-Matching in Public Transit Networks with Turn Restrictions" (Bast and Brosi, ACM SIGSPATIAL 2018), and its method is the first part of Brosi's doctoral thesis, Automated Generation of Transit Maps (2022). It is written in C++ and published under the GNU General Public Licence, version 3.

Made for timetables

It reads a whole GTFS feed and works from what a timetable already has: each trip's stops in order, their positions and names, and their times.

Each mode on its own ways

Its settings cover buses and coaches, trams and subways, trains, ferries, gondolas and funiculars, each matched only to the kind of way it runs on.

Run ahead of time

It writes the lines into the timetable's shapes.txt. Nothing is asked of any service while riders use the apps.

Fast, and tested

In the thesis it matched every trip in Germany in 8.5 minutes (not counting reading the map), and got 90% of trips right on at least nine hops in ten, against 84% for the usual distance-based method, with lines 6.9 m from the true path on average.

7How pfaedle matches a route to the roads

Map matching usually starts from a GPS trace: a position every second or so, close together. A timetable gives far less: only the stops, often hundreds of metres apart. Between two stops many paths are possible, and the job is to pick the one the bus really takes. pfaedle treats this as a hidden Markov model, the standard tool for map matching: the stops are what is observed, and where each stop really sits on the network is hidden. With the settings it ships with, it works like this:

Stop, as the timetable places it Candidate on a road Chosen path Basic line
Each stop gets candidate positions on the roads nearby (two shown per stop here). pfaedle chooses one per stop, and the roads between them, so that the whole trip costs least; the Basic line just joins the stops.
  1. A network for each mode. From the extract it builds a graph of the ways a mode may use, sorted into eight levels by their tags, each with an average speed. For buses, trunk and primary roads are level 1, secondary roads level 2, residential streets level 4 and service roads level 5, with speeds from 85 km/h on the fastest level down to 5 km/h on the slowest. OpenStreetMap's mapped bus routes are read too.
  2. Candidates for each stop. For each stop it gathers the places where the stop could be: stops and stations mapped in OpenStreetMap within 200 m, scored by how alike their names are to the timetable's, weighed with distance; the nearest points on roads within 100 m, down to service roads; and, as a last resort, the stop's own position. A candidate costs a little more the further it is from the stop, and a little more again if it isn't a mapped stop, or its name doesn't match.
  3. Hops between candidates. For each pair of candidates at consecutive stops, it finds the quickest path along the network, at each level's speed. Driving against a one-way street costs five times the time plus 5 minutes, and a banned turn 5 minutes: heavy penalties rather than outright bans. A U-turn costs 2 minutes, and stretches away from the line's own mapped bus route take a fifth longer.
  4. The timetable's times as a limit. Each hop's search stops at three times the time the timetable allows for it (at least a minute), and is widened up to three times if nothing is found. If no path fits even then, pfaedle reports "No viable hop found" and draws that hop straight.
  5. The best path overall. The candidates form one layer per stop, joined by the hops. The trip's line is the cheapest path through all the layers, one candidate per stop: a shortest-path search through the layers, which is how a hidden Markov model's most likely sequence (the Viterbi path) is found.
  6. Shared work. Trips of the same line with the same stops are merged into a tree of stop sequences and matched once, so a timetable of thousands of trips takes about a second.

8Our build, step by step

One script, scripts/osm-lines/build.mjs, builds every line. It runs on the server beside the live apps, so it is careful with memory.

StepWhat happens
1. Pick the timetablesFrom the service areas the apps serve: every BAS.MY city but Kuantan, Bas Muafakat Johor, Causeway Link, City Public Link S19, the Singapore cross-border buses and, given LTA DataMall's routes, every Singapore bus service; for trains, KTMB, KLIA Ekspres and SRT's shuttle. A new BAS.MY city is picked up at the next build.
2. Find the trip patternsA pattern is one distinct sequence of stops: a route, a direction, a variant. Every trip with that sequence shares its line, so 1,338 patterns stand for all the trips. The stops are the ones the server lists, after it merges a timetable's stops into places, so the line's stop ids are the ones the apps receive.
3. Write a small timetableOne trip per pattern, with its stops and times, as a GTFS folder for pfaedle.
4. Run pfaedleIn a container from an image pinned to one exact build, matching buses only and every trip afresh. Each run is capped at 3 GB of memory and 2 CPUs at low priority, one at a time; none starts with less than 3.5 GB free, and a run is stopped after 45 minutes.
5. Check each lineThe quality gate below. A line that fails is not kept, and the server goes on showing the timetable's own line for that pattern.
6. Pin the stopsEach stop is pinned to its point on the line, in the stops' order. A stop's choices are its nearest points on up to 8 pieces of the line and the nearest point of every pass the line makes within 250 m of it: a loop that starts and ends at its terminal passes it twice, and the first stop belongs on the first pass even where the nearest pieces all lie on the last. A line that can't pass its stops in order isn't kept. The server can then cut the line between any two stops.
7. Simplify and storePoints closer than 2 m (buses) or 4 m (trains) to the simplified line are dropped, as the eye can't see them; stop points are always kept. Each line is stored as an encoded polyline (to about a metre), in one JSON file per timetable with its build time, the map data's date, the credit and the licence.
8. ReportEach timetable's patterns kept and not kept, and why; lines with a straight piece over 1.5 km (a road pfaedle couldn't follow there); and the stations left out of train lines.
The quality gate for bus lines

A line is kept only if it passes its stops in order, every stop is within 200 m of it, and, for patterns longer than 300 m, it is between 0.7 and 3 times as long as its stops joined up. The trial's worst kept cases were a stop 115 m from its line (a pole recorded well off the road) and a two-stop route 2.5 times its straight length, because its road really goes round. A line that is too short has cut a corner; one that is far too long has wandered.

9Trains, along the track

pfaedle draws a train's line through every station, as it should. But KTMB's timetable places some stations well away from the railway, and a station in the wrong place pulls the line off the track: out to Sedenak, 509 m from the railway between Layang-Layang and Kulai; out to Kalumpang, placed about 7 km from the real station; and zigzagging to East Coast halts several kilometres off the line. So trains are drawn by a method of our own (scripts/osm-lines/railPaths.mjs), on the railway track pfaedle extracts from the map:

  1. Track. Only ways tagged railway=rail, the track KTM trains run on. Light rail, monorail, funicular, tram, disused and unbuilt track are left out. Sidings, yards, crossovers and spurs may be used but count three times their length, so the main line wins.
  2. Stations meet the track. Each station is matched to the nearest point on up to 8 nearby tracks, measured to the track itself, not to its mapped points: straight track can have points kilometres apart. KL Sentral has six tracks within 40 m, and the KLIA Ekspres line must find its own among them.
  3. Off the railway. A station with no track within 300 m is out of place, and left out of the line.
  4. The shortest way along the track. The line joins the stations in order by the shortest route along the track. A hop may be up to 3 times the straight distance, or 5 km more; a station the line can't reach in order within that is left out too.
  5. Doubling back. KTM trains don't reverse on the way, so a station that makes the line run past it and come back (by over 30% of the direct way, and over 1 km) is in the wrong place or the wrong order, and left out, the worst first. At most three stations in a row are left out.
  6. Close to the station. Where a station has several tracks nearby, the line uses the one that keeps it closest to the station: each metre between station and track counts like 5 m of track.
Station placed 509 m off the railway left out of the drawn line, kept in the timetable Track method: stays on the railway A line through every station: bends out
What happened at Sedenak, between Layang-Layang and Kulai. The black and white line is the track.

Left-out stations stay in the timetable and on the map; only the drawn line doesn't bend to them, and the server lists them with the line (skippedStops). Where stations are placed correctly, this method and pfaedle give the same line: on Komuter Utara both sit on the railway, and the track method places stations a few metres closer (17 m and 28 m on average, against 22 to 32 m). Long hops are real track, not errors: Ipoh to Kuala Kangsar is 51.7 km by rail for 25.3 km in a straight line, and Dabong to Kuala Krai 55.0 km for 27.3 km. Two settings were tuned on such cases: at 2 times the straight distance the method wrongly dropped Ipoh and Kuala Krai, and without the 5-to-1 weight lines started 261 m from Dabong and 198 m from Gua Musang, joined through a short station siding.

10Routes no timetable draws

Results

The lines in numbers

pfaedle was tried in three rounds on 26 November 2026 before anything went live, on the same server and with the same caps as the build uses today.

11The trial

Round 1: four timetables

TimetableTimePeak memoryTrips matchedStop to line
Singapore cross-border buses73 s437 MB1,565 of 1,56511.4 m
Causeway Link73 s446 MB1,015 of 1,0159.6 m
BAS.MY Kangar48 s353 MB344 of 3446.5 m
KTMB (rail)36 s131 MB265 of 26520.1 m

Stop to line: the median, over a timetable's patterns, of the average distance from each stop to the line. Most of each run (about 65 seconds) is spent reading the map file; the matching itself takes about a second per timetable.

Round 2: six more BAS.MY cities, and Komuter Utara

TimetableTimePeak memoryPatternsStop to line
Alor Setar61 s498 MB266.7 m
Kota Bharu55 s397 MB328.4 m
Kuala Terengganu49 s282 MB178.1 m
Kuching (with stand-in times)48 s293 MB226.6 m
Ipoh55 s328 MB2911.2 m
Seremban A61 s489 MB198.0 m
Seremban B73 s562 MB228.1 m

Ipoh's figure is the highest because its feed lists a separate pole for every route at shared stops. Komuter Utara's lines were good too: all 40 straight pieces over 2.5 km stay within 6 m of the real track, half within 1 m, because pfaedle draws straight track with few points.

Round 3: trains along the track

KTMB timetableTimeStationsLinesStations left outStraight gaps
Malaysia Transit's copy17 s18445230
data.gov.my's live feed54 s15686140

Every train line followed the railway with no straight gaps; each straight piece over 2.5 km is a single piece of mapped straight track (the longest, 5.8 km, crosses the Perlis and Kedah paddy belt). Kept stations sit within 150 m of their line, except two whose recorded positions are that far from the track.

12What is built today

TimetableMethodPatterns keptFile
Singapore's buses (LTA DataMall)pfaedle802 of 802943 KB
KTMB (every KTM service)Track121 of 121417 KB
BAS.MY Melakapfaedle66 of 66113 KB
Bas Muafakat Johorpfaedle57 of 5751 KB
BAS.MY Johor Bahrupfaedle45 of 4566 KB
Causeway Linkpfaedle36 of 3638 KB
BAS.MY Kota Bharupfaedle32 of 3270 KB
BAS.MY Ipohpfaedle30 of 3050 KB
BAS.MY Alor Setarpfaedle27 of 2733 KB
BAS.MY Kangarpfaedle23 of 2340 KB
BAS.MY Kuchingpfaedle23 of 2331 KB
BAS.MY Seremban Bpfaedle22 of 2253 KB
BAS.MY Seremban Apfaedle18 of 1933 KB
BAS.MY Kuala Terengganupfaedle19 of 1932 KB
Singapore cross-border busespfaedle6 of 610 KB
KLIA Ekspres and KLIA TransitTrack4 of 45 KB
Causeway Link AA1pfaedle2 of 22 KB
City Public Link S19pfaedle2 of 23 KB
SRT Padang Besar–Hat YaiTrack2 of 22 KB
19 timetables1,211 pfaedle, 127 track1,337 of 1,3381.94 MB

Built on 26 November 2026 from OpenStreetMap data until 17 November 2026 (SRT's railway: an extract of 28 July 2026); on 27 November the bus lines' stops were pinned again, as step 6 of section 8 describes, the cross-border buses' lines built again on LTA DataMall's stop positions, and those and Singapore's built again with the 160, the 950 and the 170X drawn out to JB Sentral and back (section 10). One line doesn't pass its stops in order and isn't kept: Seremban A's Desa Rhu loop. KTMB's file serves all 11 KTM services in the apps, from Komuter Klang Valley to Shuttle Tebrau and the Intercity trains to Kota Bharu. BAS.MY Johor Bahru's and Melaka's own lines already follow the roads, so their route views keep them.

13Against Google's lines

Google Directions (before)OpenStreetMap (now)
On our own mapsNot allowed (section 4.2)Allowed, with the credit
Keeping themCoordinates only, for 30 daysOurs to keep, and to share under the same licence
Which roadsGoogle's own best way between each pair of stopsThe quickest way through all the stops in order, weighing each stop's distance, road class, turns and mapped bus routes
A stop set back from the roadCould swerve onto another road to reach itPinned to the road beside it; a line too far from any stop isn't kept
TrainsThrough every station, even one placed off the lineAlong the track, leaving out stations placed off it, and reporting them
Fit with the mapGoogle's road geometry over an OpenStreetMap mapThe same roads the map draws
CostUS$5.00 per 1,000 requests after 10,000 free a monthNothing per line; about 20 minutes of our server per rebuild
Fresh roadsGoogle's current mapAs fresh as the extract: rebuilt every month or two
If it failsNo line, or a line that bends wrongThe quality gate falls back to the timetable's own line

On ordinary roads the two are very close: CW2's new line is 2.5 m from Google's on average. The difference shows where it matters to riders: at stops set back from the road, at terminals and interchanges, and on trains whose timetable puts a station in the wrong place.

14What the build found

Drawing lines carefully is also a close check of the timetables. These findings are worth sending to KTMB and data.gov.my, and are listed with every build:

KTM stations off the railway. More than 5 km off: Mela, Sg Mengkuang Baru, Kuala Gris, Kemubu, Sri Mahligai, Kalumpang (placed near Lembah Beringin), Tembeling and Padang Piol. Closer in: Sri Bintang 4.5 km, Pahi 4.4 km, To' Uban 2.9 km, Aur Gading 1.6 km, Sri Jaya 1.4 km, Kg Berkam 1.1 km, Bertam 666 m, Sedenak 509 m, Dura 412 m, Sungai Temau 341 m and Holiday Plaza 307 m.

In the wrong place or order. "Mengkuang" is timetabled between Triang and Kemayan in Pahang but placed south of Kuala Krai in Kelantan, about 330 km up the line. Kubang Rusa and Teluk Gunong are listed in swapped order, and so are Kg Telang and Pdg Tungku.

Other timetable issues. On Kuching's Q11 to Q16 every stop has the same time (section 10). KTMB's live feed has no route lines at all, and codes its five Komuter services, Shuttle Selatan among them, as trams. The KTMB copy used in the trial had 8 stop times pointing at a station (37200) missing from its stop list, and 39 Komuter trips with no stops. BAS.MY's feeds, all but Johor Bahru's and Melaka's, have one line point per stop, and some poles recorded 40 to 115 m off the road. (Hat Yai is left out of KTM's lines only because the main extract stops at the border: not a timetable error.)

In use

Serving, upkeep and licence

The lines are plain files in the server's code. The server reads them when it starts, and riders get them with no outside service in the way.

15How the apps use the lines

16Rebuilding

Lines are rebuilt when a timetable's trips change a lot, and every month or two for newer map data. The whole build takes about 20 minutes on the server:

  1. Download a fresh Geofabrik extract (about 250 MB).
  2. In a scratch copy of the code, never the copy the live server runs from, run the builder with the extract, LTA DataMall's cached bus routes and SRT's railway extract.
  3. Read the report: patterns kept and not kept, straight pieces, stations left out.
  4. Look over each area's new lines against Basic on an internal review page.
  5. Commit the files; the server reads them on its next start. Copy the Singapore, cross-border, AA1 and KTMB files to SG-JB Transit.

Per timetable a run takes about a minute and under 0.5 GB of memory; extracting the railway for the train method takes 43 seconds at a 139 MB peak, and the track method itself seconds.

17Licence and credit

18Limits and next steps

19Sources

pfaedle: github.com/ad-freiburg/pfaedle (code, default settings and README, read 27 November 2026); H. Bast and P. Brosi, "Sparse Map-Matching in Public Transit Networks with Turn Restrictions", Proceedings of ACM SIGSPATIAL 2018, pp. 480–483, doi:10.1145/3274895.3274957; P. Brosi, Automated Generation of Transit Maps, doctoral thesis, University of Freiburg, 2022, chapter 2, "Map-Matching Schedule Data", doi:10.6094/UNIFR/228990.

OpenStreetMap: openstreetmap.org/copyright (credit and licence); the Open Database Licence 1.0, opendatacommons.org/licenses/odbl/1-0; Geofabrik's Malaysia, Singapore and Brunei extract, download.geofabrik.de/asia/malaysia-singapore-brunei.html; the Overpass API, overpass-api.de.

Timetables: data.gov.my's GTFS feeds (CC BY 4.0); LTA DataMall's bus routes and stops (Singapore Open Data Licence); the GTFS reference for shapes.txt, gtfs.org.

Google Maps Platform: Service Specific Terms (version of 24 November 2026), cloud.google.com/maps-platform/terms/maps-service-terms; Terms of Service, cloud.google.com/maps-platform/terms; pricing, developers.google.com/maps/billing-and-pricing/pricing (read 27 November 2026).

Malaysia Transit's own records: how the lines are built (docs/osm-route-lines.md), the builder (scripts/osm-lines/), the line files (data/osm-lines/, built 26 November 2026, the bus lines' stops pinned again on 27 November), and the pfaedle trial report of 26 November 2026, with its three rounds.