In this series: Part II, Paths. The path of a storm is measured after it has moved. A bus has a timetable, so its position can be calculated for every minute
You will build: A bus map in its official colours, a train graph for one corridor and for all of them, the position of every bus of Jakarta at 08:15, and a picture of fourteen corridors with time as height
You need: Chapter 0, for the environment, and section 5 of Chapter 1, for lines that work in every shell. Chapter 5 explains lag and over
Time to run: The commands took about two minutes when tested, including 2.5 MB of downloads
Level: Intermediate; several tables are joined
A timetable is a table of places and times. A map shows the places without the times. The timetable at a bus stop shows the times, but for one place only. This chapter draws pictures that show both.
The data is the timetable of TransJakarta, the bus system of Jakarta. It comes as text files that do not contain the position of any bus at 08:15. A few lines of SQL calculate it.
NoteLearning objectives
By the end of this chapter you will be able to:
read a public transport feed (GTFS) directly from the web, with a point for every stop and a line for every trip;
make a colour file from the data itself;
turn “every 6 minutes from 5 to 22” into single departures, with a recursive query;
draw a train graph, with time to the right and place upwards;
calculate where every vehicle is at a given minute, and draw the path of its last minutes;
draw time as height, in a picture and in a file for Google Earth;
merge overlapping circles, so that no land is counted twice.
Before running this chapter, do section 1 of Chapter 0 and section 5 of Chapter 1. In a terminal, make a new empty folder and copy into it the files of sample-data/ch06. In this notebook, the next cell does that.
import sysimport timefrom pathlib import Path# The repository root, whether the notebook runs from en/, id/ or the root itselfROOT = Path.cwd() if (Path.cwd() /"tutorial.yml").exists() else Path.cwd().parentsys.path.insert(0, str(ROOT /"src"))import onelineT0 = time.perf_counter()WORK = oneline.start("06")print("working folder:", WORK.name, "| files copied there:", sorted(f.name for f in (ROOT /"sample-data/ch06").iterdir()))
A few short commands first, in the form of Chapter 0. This chapter has one source, and it must come from the web. Bus and train companies publish their timetables in a common form, the General Transit Feed Specification (GTFS). A feed is a zip with text files: stops, routes, trips, times. GDAL has a driver for it. The first line looks long, but it is one command, with one input and one output:
records that the coordinates are degrees. The layers come without this information, and later lines need it
CPL_VSIL_CURL_USE_HEAD NO
GDAL usually requests the size of a file first. This server answers that request with an error (ledger L51)
--burn 1 --add
draw each route with the number 1, and add where routes overlap. So each cell counts its routes
Look before moving on. The picture shows the streets that buses use. The bright streets carry the most routes. But a route is not a bus: the picture does not show whether one comes every minute or twice a day. The timetable contains that, and this chapter draws the timetable.
1. A whole bus system in one line
The first line of the warm-up has downloaded a whole bus system. This is what is in the file:
The driver does more than read. It turned stops into points and trips into lines from stop to stop, and shapes_geom holds the paths along the streets (ledger L52). What kinds of routes are in it?
ogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select route_desc kind, count(distinct route_id) routes, count(*) trips, round(avg(st_length(t.geom,1))/1000,1) mean_km from trips t join routes using(route_id) group by 1 order by 3 desc"
kind,routes,trips,mean_km
Mikrotrans,98,227,14.6
Angkutan Umum Integrasi,64,166,15.6
BRT,31,162,19.6
Transjabodetabek,18,80,31.9
Rusun,14,28,9.1
Royaltrans,13,26,18.1
Bus Wisata,3,5,8.1
BRT is bus rapid transit, with lanes of its own. Mikrotrans serves the neighbourhoods, and Transjabodetabek the cities around Jakarta (ledger L53).
Whose data is it? The feed comes from the company itself, and a public catalogue of feeds lists it as official. It names no licence, though, and the company’s website reserves its rights (ledger L53). For this reason the repository of this tutorial holds no copy, and every reader gets the feed from its source. The company replaces it from time to time. The numbers in this chapter belong to the files of 20 November 2026, and yours may differ.
2. The official colours of the routes
Passengers recognise the routes of TransJakarta by their colours, and the feed has them, in the form that web pages use: D62126 for corridor 1. A GDAL colour file needs three numbers. So let a query write the colour file:
ogr2ogr-f CSV routes.csv bus.gpkg -lco HEADER=NO -sql"select fid+0, 16*instr('123456789ABCDEF',substr(upper(route_color),1,1))+instr('123456789ABCDEF',substr(upper(route_color),2,1)), 16*instr('123456789ABCDEF',substr(upper(route_color),3,1))+instr('123456789ABCDEF',substr(upper(route_color),4,1)), 16*instr('123456789ABCDEF',substr(upper(route_color),5,1))+instr('123456789ABCDEF',substr(upper(route_color),6,1)) from routes union all select 0,13,17,27 union all select 900,70,81,107 union all select 901,50,58,80"
substr takes one digit out of the colour, and instr finds its place in the list 123456789ABCDEF. A zero is not in the list, and instr then gives 0, which is right. Sixteen times the first digit plus the second gives a number from 0 to 255.
The first column is the number of the route. fid+0 is written in this way because a plain fid does not arrive in the result (ledger L54). The three extra rows are for the background, and for two greys that section 8 will need.
Now draw every path with the number of its route, and apply the colour file:
gdal pipeline read bus.gpkg ! sql "select v, geom from (select r.fid+0 v, route_desc='BRT' brt, st_buffer(g.geom, case when route_desc='BRT' then 0.0007 else 0.00025 end) geom from shapes_geom g join trips using(shape_id) join routes r using(route_id)) order by brt" ! rasterize --attribute-name v --init 0 --ot Int16 --size"5400,4800"--extent"106.65,-6.4,107.01,-6.08" ! edit --nodata none ! color-map --color-map routes.csv ! materialize ! resize --size"1800,1600"-r average ! write network.png --overwrite
Look before moving on. The thick lines are the BRT, and most of the thin blue net is Mikrotrans. The pale yellow lines go to the cities around. All colours come from the feed. If the company changes one, the map changes after the next download.
3. From a timetable to a day
A map like this needs no timetable. The next pictures need one, so look at how the feed stores time:
ogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select trip_id, trip_short_name, start_time, end_time, headway_secs, exact_times from frequencies join trips using(trip_id) where trip_id in ('1-R07','1-R09','1K-R01') order by 1, 3"
trip_id,trip_short_name,start_time,end_time,headway_secs,exact_times
1-R07,Blok M - Kali Besar Barat,"00:00:00",23:59:59,"360","0"
1-R09,Blok M - Kota,"05:00:00",10:00:00,"474","0"
1K-R01,Cibubur - Blok M,"05:45:00","06:15:00","600","0"
1K-R01,Cibubur - Blok M,"06:15:00","06:50:00","300","0"
1K-R01,Cibubur - Blok M,"06:50:00","07:40:00","600","0"
1K-R01,Cibubur - Blok M,"07:40:00","08:05:00","1500","0"
1K-R01,Cibubur - Blok M,"08:05:00","08:15:00","600","0"
1K-R01,Cibubur - Blok M,"08:15:00","08:20:00","300","0"
1K-R01,Cibubur - Blok M,"08:20:00","09:20:00","600","0"
There is no list of departures. The feed has a pattern, and a rule for repeating it: 1-R07 starts every 360 seconds, day and night. 1K-R01 changes its interval several times in a morning.
And not every trip runs every day. The table calendar shows which group runs on which days:
ogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select service_id, monday mon, wednesday wed, saturday sat, sunday sun, start_date, end_date, (select count(*) from trips t where t.service_id=c.service_id) trips from calendar c"
Now calculate a full day from the rules: Wednesday, 2 December 2026. A recursive query starts with the first departure of each rule, and then adds the interval again and again until the rule ends:
ogr2ogr-update-overwrite bus.gpkg bus.gpkg -sql"with recursive d(trip_id,t,until,step) as (select trip_id, unixepoch(start_time)-unixepoch('00:00'), unixepoch(end_time)-unixepoch('00:00'), headway_secs+0 from frequencies join trips using(trip_id) join calendar using(service_id) where wednesday=1 and '2026-12-02' between start_date and end_date union all select trip_id, t+step, until, step from d where t+step<until) select trip_id, t from d"-nln dayogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select count(*) departures, count(distinct trip_id) patterns, time(min(t),'unixepoch') first, time(max(t),'unixepoch') last from day"
a time such as 05:30:00 as seconds since midnight. Seconds are easy to add and compare
the part before union all
the first departure of every rule that is valid on that day
the part after it
takes each departure found so far and adds one interval, as long as the rule lasts
About 700 rules have become 65,000 departures. One more table is needed: for each stop of a pattern, the seconds since the bus left its first stop.
ogr2ogr-update-overwrite bus.gpkg bus.gpkg -sql"select trip_id, route_id, route_desc kind, stop_sequence q, stop_name, unixepoch(departure_time)-min(unixepoch(departure_time)) over (partition by trip_id) s, p.geom from stop_times join trips using(trip_id) join routes using(route_id) join stops p using(stop_id)"-nln call -nlt POINTogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select q, stop_name, s from call where trip_id='1-R07' and q<5 order by 1"
From here on only an addition is needed. A bus that leaves at t is at a stop at t+s.
How close is this to a real day? The column exact_times was 0. In GTFS this means that the company tries to keep the interval, and not the minute on the clock (ledger L55). This chapter assumes that the first bus of each pattern leaves exactly when its rule begins. So the pictures show a day that is possible under the timetable, and not where the buses really were.
Is there a rush hour? Count the departures in some hours of the day:
ogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select t/3600 hour, count(*) departures from day where t/3600 in (3,5,8,11,14,17,20,22) group by 1"
Look before moving on. The numbers for the day and for the night are very different, but during the day almost nothing changes. At 8 in the morning the timetable has about as many departures as at 2 in the afternoon.
4. The train graph
Put time on the x axis and the place along the route on the y axis. Each bus becomes one slanted line. Railways already used such drawings in the 19th century. A famous one shows the trains between Paris and Lyon, in a book by Étienne-Jules Marey. He wrote that the idea was not his own, and named a man called Ibry as its author (ledger L56).
Corridor 1 runs from Blok M in the south to Kota in the north, so latitude can serve as the y axis. Here is its early morning, from 4 to 8:
gdal pipeline read bus.gpkg ! sql "with recursive h(x) as (select 4 union select x+1 from h where x<8), p as (select trip_id, s, 17*st_y(geom) y, lag(s) over (partition by trip_id order by q) s0, 17*lag(st_y(geom)) over (partition by trip_id order by q) y0 from call where route_id='1') select case when y>y0 then 3 else 2 end v, st_buffer(makeline(makepoint((t+s0)/3600.0,y0),makepoint((t+s)/3600.0,y)),0.003) geom from p join day using(trip_id) where y0 is not null union all select 1, st_buffer(makeline(makepoint(x,-107),makepoint(x,-104)),0.0035) from h union all select 1, st_buffer(makeline(makepoint(4,17*st_y(geom)),makepoint(8,17*st_y(geom))),0.0035) from call where trip_id='1-R07' and stop_name in ('Blok M','Dukuh Atas','Monumen Nasional','Kali Besar') union all select 4, st_buffer(makeline(makepoint((21600+s0)/3600.0,y0),makepoint((21600+s)/3600.0,y)),0.009) from p where trip_id='1-R07' and y0 is not null" ! edit --crs none ! rasterize --attribute-name v --init 0 --ot Byte --size"5400,2790"--extent"3.98,-106.2,8.02,-104.1127" ! edit --nodata none ! color-map --color-map graph.txt ! materialize ! resize --size"1800,930"-r average ! write graph.png --overwrite
How to read it. Start with the light grey grid, and then look at the diagonal lines.
In the picture
Meaning
the five vertical grey lines
4, 5, 6, 7 and 8 o’clock, from left to right
the four horizontal grey lines
four stations, from the bottom: Blok M, Dukuh Atas, Monumen Nasional and Kali Besar, which is near Kota
each diagonal line
one bus. Orange goes north, which is up, and blue goes south
the thick white line
one bus, selected as an example
Follow the white bus. It leaves Blok M, the lowest horizontal line, at 6 o’clock exactly. It crosses the line of Dukuh Atas, and then the one of Monumen Nasional. It reaches Kali Besar, the highest line, a little after 7. On its way it crosses many blue lines. Each of these crossings is a bus that goes in the opposite direction.
Look before moving on.
Soon after 5, the diagonal lines become denser. Some patterns, such as 1-R09, run only in the morning.
Small waves begin at the same time, just above the line of Monumen Nasional. These are buses that leave the corridor to the west, by way of Petojo, and come back to it. Their way north goes a little south in between.
Some diagonal lines lie very close together, with a gap after them. Several patterns share the road, each with its own interval, and sometimes their buses arrive at nearly the same time. At a station, that means three buses and then none.
Between Blok M and Dukuh Atas, the white line bends and is less steep for a while. Is the bus slower there?
In a train graph a steep line is a fast bus. But this graph has a simplification: the y axis is latitude, and not the distance along the road. So calculate the speed itself, between neighbouring stations:
ogr2ogr-update-overwrite bus.gpkg bus.gpkg -sql"select * from (select trip_id, route_id, kind, q, stop_name, s, lag(s) over (partition by trip_id order by q) s0, makeline(lag(geom) over (partition by trip_id order by q), geom) geom from call) where s0 is not null"-nln leg -nlt LINESTRING -a_srs EPSG:4326ogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select stop_name next_stop, round(3.6*st_length(geom,1)/(s-s0),1) km_per_hour from leg where trip_id='1-R07' and q between 4 and 13 order by q"
next_stop,km_per_hour
Senayan Bank Jakarta,12.4
Polda Metro Jaya,12.2
Bendungan Hilir,12.4
Karet,12.3
Dukuh Atas,12.3
Tosari,12.4
Bundaran HI Astra,10.9
MH Thamrin,12.2
Kebon Sirih Arah Utara,12.2
Monumen Nasional,12.2
Nearly the same speed everywhere, about 12 km/h. The line is less steep because the road turns north-east there, and a bus on it gains less latitude for each kilometre.
The table also shows something about the timetable. No bus in a city drives at the same speed from station to station. These times were most likely calculated from the distance, and not measured.
5. All BRT routes in one graph
What is the result if all BRT routes go into one such graph, each in its own colour? Many of them do not run from north to south, so the picture is not suitable for planning. It does show the structure of the whole network. Here are the three hours from 5 to 8:
gdal pipeline read bus.gpkg ! sql "select v, geom from (select r.fid+0 v, t, st_buffer(makeline(makepoint((t+s)/3600.0, 10*st_y(c.geom))),0.001) geom from (select * from call where kind='BRT' order by trip_id, q) c join day d using(trip_id) join routes r using(route_id) where t between 7200 and 28800 group by d.fid) order by t" ! edit --crs none ! rasterize --attribute-name v --init 0 --ot Int16 --size"5400,2850"--extent"5,-63.14,8,-61.05" ! edit --nodata none ! color-map --color-map routes.csv ! materialize ! resize --size"1800,950"-r average ! write cloth.png --overwrite
Every line in the picture is a bus. A route from west to east hardly changes its latitude, and becomes a horizontal band. Routes from north to south are the slanted lines that cross the bands. The distance between two lines next to each other is the interval between two buses.
group by d.fid makes one line for each departure, and the outer order by t puts later buses on top of earlier ones.
6. Every bus at 08:15
The graph showed one route at all times. This section shows all routes at one time. At 08:15, or 29,700 seconds after midnight, each bus is somewhere between two stops. The layer leg from section 4 has a line for each such piece, with the seconds at both ends. The part of the piece that the bus has already driven is a simple fraction:
ogr2ogr-update-overwrite bus.gpkg bus.gpkg -sql"select trip_id, kind, st_line_interpolate_point(geom, (29700-t-s0)*1.0/(s-s0)) geom from leg join day using(trip_id) where t+s0<=29700 and t+s>29700"-nln now -nlt POINT -a_srs EPSG:4326ogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select kind, count(*) vehicles from now group by 1 union all select 'all', count(*) from now order by 2 desc"
kind,vehicles
all,5808
Mikrotrans,2890
BRT,1212
Angkutan Umum Integrasi,889
Transjabodetabek,694
Rusun,90
Royaltrans,31
Bus Wisata,2
Is it right? There is another way to count. If a trip takes 60 minutes, and a bus leaves every 6 minutes, then 10 buses are on the road at any time. So divide the length of each trip by its interval, and add up. This does not need the positions:
ogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select round(sum((min(29700,z)-max(a,29700-dur))*1.0/step)) vehicles from (select trip_id, unixepoch(start_time)-unixepoch('00:00') a, unixepoch(end_time)-unixepoch('00:00') z, headway_secs+0 step from frequencies) join (select trip_id, max(s) dur from call group by 1) using(trip_id) where trip_id in (select trip_id from day) and a<=29700 and z>29700-dur"
vehicles
5798
The two numbers differ by ten vehicles, or 0.2 percent. min and max in this line count only the time in which the rule was valid.
Now the picture. A dot alone does not show where a bus is going, so each dot also gets the path of its last three minutes, in colours that are darker for older positions. line_substring cuts a piece out of a line, from one fraction to another:
gdal pipeline read bus.gpkg ! sql "with k(e) as (values (29700),(29640),(29580)) select 1 v, st_buffer(geom,0.00015) geom from shapes_geom union all select * from (select case when kind='BRT' then 8 else 4 end-(29700-e)/60 v, st_buffer(line_substring(geom, max(0.0,(e-60-t-s0)*1.0/(s-s0)), min(1.0,(e-t-s0)*1.0/(s-s0))), 0.0004) geom from leg join day using(trip_id), k where t+s0<e and t+s>e-60 order by 1) union all select * from (select case when kind='BRT' then 9 else 5 end v, st_buffer(geom,0.0006) geom from now order by 1)" ! rasterize --attribute-name v --init 0 --ot Byte --size"5400,4800"--extent"106.68,-6.37,106.995,-6.09" ! edit --nodata none ! color-map --color-map minute.txt ! materialize ! resize --size"1800,1600"-r average ! write minute.png --overwrite
Look before moving on. There is no street map in this picture, only the bus routes in a dark grey. The positions of the buses show the main roads of the city. The orange dots are BRT, and the blue ones are all other services.
On the right and on the left, some rows of blue dots cross the land in a straight line. Between two stops, this map moves a bus along a straight line and at an even speed. Marey already noted that the drawings of his time did the same (ledger L56). On motorways the stops are many kilometres apart, and the straight line leaves the road.
To see another minute, change 29700, and the two numbers after it. For a film, make a picture for every minute, and join them with a tool for videos.
7. Where can you go without changing?
Where is the busiest place in the system? Join the day with the stops:
ogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select stop_name, count(*) calls_a_day, count(distinct route_id) routes from day join call using(trip_id) group by 1 order by 2 desc limit 5"
stop_name,calls_a_day,routes
Cawang Sentral,5388,7
Transjakarta Tanah Abang 1,4624,8
Cawang,4466,9
Kampung Melayu,3936,8
Cawang Cililitan,3831,7
At Cawang Sentral, a bus stops nearly four times a minute, day and night together. How far can you go from there without changing? Join call with leg. The first is the place where you get on, and the second is every later piece of the same trip. The colour is the time since you got on, and the trips of all days of the week are in it:
gdal pipeline read bus.gpkg ! sql "select 1 v, st_buffer(geom,0.00018) geom from shapes_geom union all select * from (select max(2, 8-(l.s-a.s)/900) v, st_buffer(l.geom,0.0008) geom from call a join leg l on l.trip_id=a.trip_id and l.s0>=a.s where a.stop_name='Cawang Sentral' order by l.s-a.s desc) union all select 8, st_buffer(geom,0.0025) from call where stop_name='Cawang Sentral'" ! rasterize --attribute-name v --init 0 --ot Byte --size"5400,4800"--extent"106.65,-6.4,107.01,-6.08" ! edit --nodata none ! color-map --color-map ride.txt ! materialize ! resize --size"1800,1600"-r average ! write ride.png --overwrite
The palest colour is the first quarter of an hour, and each darker one is another quarter. The darkest violet is everything beyond 90 minutes. The slow pieces are drawn first, so that the fastest way ends up on top.
Is the busiest stop also the one with the most places to go? Count the stops that can be reached in one ride:
ogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select a.stop_name, count(distinct b.stop_name) stops_in_one_ride, count(distinct a.route_id) routes from call a join call b on a.trip_id=b.trip_id and b.q>a.q group by 1 having a.stop_name='Cawang Sentral' or stops_in_one_ride>400 order by 2 desc"
stop_name,stops_in_one_ride,routes
Jln. Taman Jatibaru Timur,494,14
Term. Tj. Priok 1,414,10
Term. Senen,405,9
Kel. Senen,404,9
Bangau VI,403,9
Cawang Sentral,112,8
Look before moving on. No, by a large difference. At the first stops in this list, many routes with many small stops meet. A place can have very many buses to few places, or fewer buses to very many.
8. Time as height
So far, time was an axis, a moment or a colour. It can also be height. Let one bus start in each of the fourteen corridors, all at the same moment, and let the height of each line increase with the travel time. The first line selects the buses, from the trip with the shortest interval in each corridor:
ogr2ogr-update-overwrite bus.gpkg bus.gpkg -sql"select r.fid+0 v, r.route_id, t.trip_id, trip_short_name, min(headway_secs+0) step from frequencies join trips t using(trip_id) join routes r using(route_id) where route_desc='BRT' and route_id+0=route_id and t.trip_id in (select trip_id from day) group by r.route_id"-nln onegdal pipeline read bus.gpkg ! sql "with p as (select v, q, 0.9*st_x(geom)-0.45*st_y(geom)-98.937 x, 0.25*st_x(geom)+0.5*st_y(geom)-23.6075 y, 0.00001*s z from call join one using(trip_id) order by v, q) select 900 v, st_buffer(makeline(makepoint(x,y)),0.0007) geom from p group by v union all select 901, st_buffer(makeline(makepoint(x,y),makepoint(x,y+z)),0.00015) from p union all select * from (select v, st_buffer(makeline(makepoint(x,y+z)),0.0009) from p group by v order by max(z) desc) union all select v, st_buffer(makepoint(x,y+z),0.0015) from p" ! edit --crs none ! rasterize --attribute-name v --init 0 --ot Int16 --size"5400,3510"--extent"-0.15,-0.075,0.15,0.12" ! edit --nodata none ! color-map --color-map routes.csv ! materialize ! resize --size"1800,1170"-r average ! write rise.png --overwrite
route_id+0=route_id keeps the plain numbers. It is true for 10, and false for a variant such as 10H.
How does a flat picture show a third dimension? With two formulas of school geometry:
x = 0.9*east - 0.45*north turns the map, and y = 0.25*east + 0.5*north makes it flatter, as it would look from the side. The numbers at the end only move the middle of the city to zero.
The height is added to y. Every second moves the line up a little.
The grey lines are the routes on the ground, and each vertical line joins a station to the moment when the bus is there.
Look before moving on. The length of a vertical line is a time, and the highest ends belong to the longest rides:
ogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select route_id corridor, trip_short_name ride, max(s)/60 minutes, count(*) stops from one join call using(trip_id, route_id) group by 1 order by 3 desc limit 4"
The driver gives some column names a special meaning. altitudeMode sets how the heights are measured, here from sea level, extrude draws a wall from the line down to the ground, and OGR_STYLE contains the official colour. Open rise.kml in Google Earth and tilt the view.
9. Who can walk to a bus?
A line for everyday work. How much land lies within 500 metres of a stop? The distance is our choice, and it is measured in a straight line. Make the circles in metres, and merge them:
ogr2ogr-update-overwrite bus.gpkg bus.gpkg -sql"select location_type, st_union(st_buffer(st_transform(geom,32748),500)) geom from stops group by 1"-nln walk -nlt PROMOTE_TO_MULTI -a_srs EPSG:32748ogr2ogr-f CSV /vsistdout/ bus.gpkg -sql"select case location_type when 1 then 'stations' else 'stops and platforms' end kind, count(*) points, round(count(*)*3.14159*0.25) sum_of_circles_km2, (select round(st_area(geom)/1e6) from walk w where w.location_type=s.location_type) merged_km2 from stops s group by 1"
kind,points,sum_of_circles_km2,merged_km2
stations,274,215,144
stops and platforms,7875,6185,683
Part
Meaning
st_transform(geom,32748)
from degrees to metres. EPSG:32748 is UTM zone 48 south, which covers Jakarta
location_type
1 is a station, and 0 is a single stop or a platform (ledger L55)
st_buffer(...,500)
a circle of 500 metres around each stop
st_union with group by
merges all circles of a group into one shape, so that shared land counts once
Look before moving on. Added up, the circles around all stops have nine times the area of the land that they cover. A sum of circles is therefore the wrong number for this question. Draw both shapes:
gdal pipeline read bus.gpkg ! sql "select location_type+1 v, geom from walk union all select 3, st_buffer(st_transform(geom,32748),70) from stops where location_type=1 order by 1" ! rasterize --attribute-name v --init 0 --ot Byte --size"5400,4800"--extent"683000,9292000,722375,9327000" ! edit --nodata none ! color-map --color-map walk.txt ! materialize ! resize --size"1800,1600"-r average ! write walk.png --overwrite
Orange is the land near a station, and blue-grey is the land near any other stop. The dark holes inside the city are the interesting part. Some may be places where nobody lives, and others may be gaps in the service. This data does not show which.
Try it yourself
Your own city. The Mobility Database lists feeds from many countries. Many of them list every departure, and have no frequencies. Then day is simply each trip with the time of its first stop.
Sunday. Change the date and the day of the week in section 3. How many departures are left?
Midnight. Draw the map of section 6 for 02:00, which is 7200 seconds. Which lines are still there?
Your stop. Use the name of your stop in the line of section 7.
Checkpoint
The cell below stops with an error if the results are not what this chapter expects. The limits are wide, because the feed changes.
import csvimport iodef rows(sql, dataset="bus.gpkg"):"""The rows of a query, as dictionaries."""returnlist(csv.DictReader(io.StringIO(oneline.run(f'ogr2ogr -f CSV /vsistdout/ {dataset} -sql "{sql}"'))))n =int(rows("select count(*) n from day")[0]["n"])assert40_000< n <100_000, "section 3 should make about 65,000 departures"back =int(rows("select count(*) n from leg where s<=s0")[0]["n"])assert back ==0, "no bus should arrive before it left"# Every bus on the road must be on exactly one piece of its tripnow, trips = (int(rows(q)[0]["n"]) for q in ("select count(*) n from now","select count(*) n from day join (select trip_id, max(s) dur from call group by 1) using(trip_id) where t<=29700 and t+dur>29700"))assert now == trips, "the number of dots should be the number of trips under way"assertint(rows("select count(*) n from one")[0]["n"]) >=13, "section 8 should find the numbered corridors"pictures = ("network.png", "graph.png", "cloth.png", "minute.png", "ride.png", "rise.png", "walk.png")assertall((WORK / f).stat().st_size >10_000for f in pictures)print(f"checkpoint passed: {n:,} departures; {now:,} vehicles under way at 08:15, each in exactly one place")print(f"time since the first cell: {time.perf_counter() - T0:.0f} s")
checkpoint passed: 65,218 departures; 5,808 vehicles under way at 08:15, each in exactly one place
time since the first cell: 118 s
Troubleshooting
Symptom
Cause
Fix
GTFS: required .txt files missing and a response code of 500
The server does not answer GDAL’s request for the size
The date lies outside the calendar of the feed, or the day of the week does not match it. No row was found, and no table was made
Look at the table calendar
Trips late at night are missing
Some feeds continue to count after midnight, such as 25:10:00, and unixepoch does not accept such a time
substr(x,1,2)*3600+substr(x,4,2)*60+substr(x,7,2)
The first line stops with an error
The connection to the server was lost
Download the zip with a browser, and write GTFS: and its file name in place of the address
What comes next
This chapter calculated places from times, and drew both in one picture. Some of the bus routes cross the border between two districts. In Chapter 7: Simplifying borders without gaps the subject is polygons that share their borders, and how to change their shape without gaps or overlaps between them.
Timetable: PT Transportasi Jakarta, GTFS feed with files of 20 November 2026, read on 3 December 2026. The pictures were calculated from it for this tutorial, and the company has no part in them.