Generating Chinese GTFS Feeds

Wednesday, December 2, 2026

link Crash Course on Political Relations

If you’ve ever traveled in China, or started planning to do so, you’ve likely quickly come across this particular problem.

Back in 2009 Google proudly supported transit planning in China. However, sometime in 2019 transit planning stopped working, with minimal communication from the company. This change was years in the making, with Google signaling their interest in pulling out of China and closing Chinese offices in 2010 due to fears about censorship by the government. Going forwards, google.cn was deprecated and redirected or linked to google.com.hk, which did not censor search results. From 2010 to 2019 Chinese transit was on life support as China became a decreasingly important market for Google.

Another place you can observe that lack of interest is in the map itself. The misalignment between the street grid and locations of destinations and satellite imagery makes it nearly unusable.

Software developer Leif Gehrmann made a great visual depicting this misalignment:

So, wait, if we know how to reverse this misalignment, considering we can make this chart in the first place, why doesn’t Google do it? Well, in 2002 China banned private mapping. So all authorized maps of China outside the country are contracted from a Chinese company that works directly with the government. Google is known to have done this with the entity MapABC, under the AutoNavi or amap.com umbrella. As a further consequence of this legistlation all coordinates are published as GCJ-02, a geodetic datum that offsets coordinates "randomly". The Chinese company cannot reverse the obfuscation because they would be legally punished and the foreign country cannot reverse the obfuscation because they would lose their fragile contract enabling them to have the data in the first place. As a result, if a foreign company wishes to publish a world map with any level of accuracy they must concede and publish as-is.

Of course, the offset is not even close to random, clear from the visual. It is clearly based on a set of sinusodal octaves. A library named eviltransform has an iterative algorithm (that may have been leaked at some point) that can convert closely between GCJ-02 and WGS-84 (used by most of the rest of the world). One iteration of this algorithm is within 2 meters of accuracy. Here is a succinct implementation of that evil, censored algorithm:

 1import math
 2
 3def gcj2wgs(lng, lat):
 4    if not (72.004 <= lng <= 137.8347 and 0.8293 <= lat <= 55.8271):
 5        return lng, lat
 6    a, ee = 6378245.0, 0.00669342162296594323
 7    def f(x, y):
 8        r = math.sqrt(abs(x))
 9        return (-100+2*x+3*y+.2*y*y+.1*x*y+.2*r +
10                (20*math.sin(6*x*math.pi)+20*math.sin(2*x*math.pi))*2/3 +
11                (20*math.sin(y*math.pi)+40*math.sin(y/3*math.pi))*2/3 +
12                (160*math.sin(y/12*math.pi)+320*math.sin(y*math.pi/30))*2/3)
13    def g(x, y):
14        r = math.sqrt(abs(x))
15        return (300+x+2*y+.1*x*x+.1*x*y+.1*r +
16                (20*math.sin(6*x*math.pi)+20*math.sin(2*x*math.pi))*2/3 +
17                (20*math.sin(x*math.pi)+40*math.sin(x/3*math.pi))*2/3 +
18                (150*math.sin(x/12*math.pi)+300*math.sin(x/30*math.pi))*2/3)
19    dlat, dlng = f(lng-105, lat-35), g(lng-105, lat-35)
20    rad = lat/180*math.pi
21    m = math.sin(rad)
22    magic = 1 - ee*m*m
23    sqrtm = math.sqrt(magic)
24    dlat = (dlat*180)/((a*(1-ee))/(magic*sqrtm)*math.pi)
25    dlng = (dlng*180)/(a/sqrtm*math.cos(rad)*math.pi)
26    return lng-dlng, lat-dlat

The question now is what alternatives are available to us.

link A Cluttered Design

The two dominant mapping apps with transit planning in China are Amap (known as Gaode Maps) and Baidu Maps. Both dominate the Chinese market collectively.

Neither have english support on their web version, and only Amap Global (a relatively young app) has english support on mobile. A few more glaring problems exist, however. The Spiegel Institute performed a study on the UI and UX of Chinese mapping apps and found that Gaode and Baidu both have unnecessary visual noise on their homepage from the number of different features highlighted there. They also have lower LODs at greater zoom levels. I wanted a more useful interface for my approach to traveling.

link Making My Own

To start I needed to decide what direction to go: forge requests to Baidu Maps (which include both walking and transit directions) or ingest timetable data into a routing engine. I started with the first.

The most important query appears to be this one, which returns a JSON blob describing the route (including buses, metros, trains and walking).

1https://maps.baidu.com/?newmap=1&reqflag=pcmap&biz=1&from=webmap&da_par=direct&pcevaname=pc4.1&qt=bt&c=340&sn=1$$$$12697735.96,2560960.76$$深圳市$$0$$$$&en=1$$$$12679933.58,2560260.79$$广东省深圳市南山区南山街道听海大道$$0$$$$&sc=340&ec=340&pn=0&rn=5&exptype=dep&exptime=2026-11-30 13:54&version=5&da_src=&da_src=pcmappg.searchBox.button&tn=B_NORMAL_MAP&nn=0&auth=XfY8g@9SLfBxeON7UZTVf9g5azGWQbUFuxNTLVNzVHBtCRVP8VVRXFzR8yEG8e1aDvkGcuVtvvhguVtvyheuLtB2QKAZzvCQMuVtvIPcuxtw8wkvFuzajPyYxv@vcuVtvc3CuVtvcPPuVtveGvuLztexZFTHrwzJvIswVH32wiKDv7uvhgMuzVVtvrMhuHLtSrrlrIKHf0wd0vyOUM7MUA7S&seckey=PUpOXvdxmeJkv6dGFBa/BExYF1nZrVd4JhtwUBfdfj4=,G5fcxUt4hXQDWRqN023ko95S5WSslUDq3V_wWLfR2oT9pmpqgqNlYifbSerqk59d1-i9nRtvsC8YtoCgFp_O5j7WSRaQ8BZdsccEhCgA_kxJjIO2TNz-n10tywIe9EhH6GZ2REKCX8OEbL8A88JOP1uBeg9X2Ky1tkU0zHQS74g6ZsHitPJpnMd2zIPEtpubyMR8Wr5wx7kyeKfR3vUvIiMT_QxXqUU98HhN3XDtQx3sDEpqPboom8JO-0KgUynpPAiKi9QE9IjAr1dsK58D9m4VhD4dCwzSmyirTkEpn9K5-SU1ADmjXp-BfVQf1tmD&ie=utf-8&l=12&b=(12652930.293993805,2540236.544628481;12702708.228730652,2581285.385371519)&t=1796072055223&newfrom=zhuzhan_webmap

Broken down, I found that this URL means the following:

PartMeaning
maps.baidu.com/?newmap=1Prefixes every route request, even when changing the origin or destination of an existing search
reqflag=pcmapUnknown
biz=1Unknown
from=webmapUnknown
da_par=directUnknown
pcevaname=pc4.1Client version identifier. Hasn’t changed in over a year
qt=btQuery type. bt for Bus/Transit, nav for driving, walk for walking, cycle for biking
c=340Current city as a UID (Shenzhen here)
sc=340Start city UID
ec=340End city UID
sn=1$$$$12697735.96,2560960.76$$深圳市$$0$$$$Starting coordinate as BD09 Mercator 12697735.96,2560960.76, with display name 深圳市 (Shenzhen City)
en=1$$$$12679933.58,2560260.79$$广东省深圳市南山区南山街道听海大道$$0$$$$Ending coordinate as BD09 Mercator 12679933.58, 2560260.79, with display name 广东省深圳市南山区南山街道听海大道 (Tinghai Avenue, Nanshan Subdistrict, Nanshan District, Shenzhen, Guangdong)
pn=0Page number of results
rn=5Max number of route alternatives returned
exptype=dep"Expected" type. Arrival seems to be unused
exptime=2026-11-30 13:54Departure time as an ISO 8601 string in China Standard Time. The current time if blank
version=5Unknown. Hasn’t changed in over a year
da_src=&da_src=pcmappg.searchBox.buttonUI entry point that triggered the request (here the search box button)
tn=B_NORMAL_MAPMap layer name. B_NORMAL_MAP for the default, B_EARTH_MAP for satellite
nn=0Unknown.
auth=XfY8g@…Session auth token (extracted from window.AUTH in the map.baidu.com HTML payload)
seckey=PUpO…,G5fc…Unknown secure credential. Baidu Maps accepts -1,-1 for this value.
ie=utf-8Text encoding.
l=12Zoom level.
b=(12652930.29,2540236.54;12702708.23,2581285.39)Viewport bounding box (bottom left, top right) in BD09 Mercator.
t=1796072055223Client unix timestamp in milliseconds
newfrom=zhuzhan_webmapReferrer. This is the homepage

The most important discoveries were of the BD09 encoding and the city UID scheme. This meant I could create arbitrary routes between coordinates as long as I figured out how to convert BD09 to WGS84 (the global standard used by most mapping apps) and whether I needed to figure out how to identify city UIDs from coordinates.

The payload returned by that request is like the following:

  1{
  2    "exts": [
  3        {
  4            "arrive_time": "2026-11-30T14:34:13",
  5            "depart_time": "2026-11-30T14:00:00",
  6            "distance": 19185,
  7            "kind": 0,
  8            "price": 500,
  9            "subway_price": 500,
 10            "time": 2053,
 11            "tip": 0,
 12            "tip_label": "<font color=\"#ffffff\">\u6700\u5feb<\/font>",
 13            "tip_label_background": "#67C395",
 14            "tip_label_type": 12,
 15            "walk_distance": 768,
 16            "walk_time": 643
 17        }
 18    ],
 19    "lines": [
 20        [
 21            {
 22                "distance": 18417,
 23                "ed_uid": "6f2302f026ab823914b54b51",
 24                "endTime": "00:20",
 25                "geo": ".=MAAlLBEnsPPA;|.=OsurLBCEzQPA;|-=OsurLBCEzQPAKXIgaPAgg\/QgtRAgiJEg4LAgRAFgUtAgcpNg8HCgwIPgwoCgsGHgkMBg0iHg2ZBgYaEgfwAggFAg+AAgBAAgAAAARCAgXAAg9fDgemAgsIOg2kCgNKOg0ECgw1KgMcBg2hIgAOBgARFg7EBguoCgVUBg25BgI9BgolCgXUDgT1CgJIDgWDEg3VCgswDgxdBg12DgnBBgiWKgyzBgU6JgoMCgrJEgOUBgeZIgptFg5PEg45Bge7CgDnAgeeMgScAggcGgDOAgQ7HgGYAgkNDg+BAgFAAgAAAAnvGgJPAgCwGgQGAgQvGgIcAgIyCgooAgg7CgwEBg4SCgIACgQDCggJCg4SCgwBDgwzDgY1EgYfCgQcCgYfCgQcCgAIDggJCgwMEgIOBgYcEgwSAA4oEgIcAAYAGg4gBAYqDgYGCAzfGglXCA+nFgldBABAAgAAAAcREgOABA4PEgUtAAYLHg4uAA0JHgs2AAgfEgg+AAUGBggMAAMDBgkaAAgXBg8VBA0rBg0dCAklBgM1BAwdBgcJBAw2BgUGBAI9Dg4HBAVFIg\/RCADAAgBAAArgEguOBASJDgQAAgAPIgqvCghbGg6fBgOaQg5JAgCKKgvZAA4aFgQRBAQLFgYtBAIkDggJCAYRDg4SCAolCgAvCAoBBgoXDAIcAgIyCAOqAga3UA5AAg1kDAAAAANAAA;",
 26                "kind": 0,
 27                "last_station": "\u78a7\u5934",
 28                "name": "\u5730\u94c111\u53f7\u7ebf(\u673a\u573a\u7ebf)(\u7ea2\u5cad\u5357-\u78a7\u5934)",
 29                "st_uid": "c26a84bf051c7bd9eedfca0a",
 30                "startTime": "06:09",
 31                "station_num": 5,
 32                "time": 1260,
 33                "timetable": "06:00-23:19  ",
 34                "timetable_ext": "",
 35                "tip": 0,
 36                "totalPrice": 0,
 37                "type": 1,
 38                "uid": "51a8d3da63047064fa42b2d8",
 39                "zonePrice": 0,
 40                "lineColor": "#826068"
 41            },
 42            19185,
 43            2053,
 44            500,
 45            768,
 46            643,
 47            19.6276,
 48            0,
 49            "2026-11-30T14:00:00",
 50            "2026-11-30T14:34:13",
 51            0
 52        ]
 53    ],
 54    "stops": [
 55        [
 56            {
 57                "getOff": {
 58                    "geo": ".=8SzrLBAc7QPA;",
 59                    "name": "\u8d77\u70b9",
 60                    "uid": "2bfcb14cf5cb2cfcc23644f2"
 61                },
 62                "getOn": {
 63                    "geo": ".=OsurLBEEzQPA;",
 64                    "name": "\u798f\u7530",
 65                    "uid": "c26a84bf051c7bd9eedfca0a"
 66                },
 67                "walk": {
 68                    "direction": 0,
 69                    "distance": 629,
 70                    "ename": " 20\u5165\u53e3",
 71                    "fill": 0,
 72                    "geo": ".=YlurLBY\/yQPA;|.=oSzrLBWf8QPA;|-=oSzrLBMe7QPAg1BgwDAg6NAgVAAgIhAgyAAgiABgFBAgCRAgXOAAEOAgzKAAWRAgxPAAUAAgwSAAkBAg5BAA4VAAiJAAAAAAKAAgAAAAsEAgAAAAAAAAAAAAglAgAAAAAAAA0gAgAAAA8KAgIDAAAAAAAAAAQGAAw4IgkBAgAAAAAAAAIDAA;",
 73                    "real": 1,
 74                    "sname": "",
 75                    "time": 527,
 76                    "wfi": ""
 77                }
 78            },
 79            {
 80                "getOff": {
 81                    "geo": ".=OAAlLBg8qQPA;",
 82                    "name": "\u524d\u6d77\u6e7e",
 83                    "uid": "6f2302f026ab823914b54b51"
 84                },
 85                "getOn": {
 86                    "geo": ".=UrAlLBQWqQPA;",
 87                    "name": "\u7ec8\u70b9",
 88                    "uid": "2bfcb14cf5cb2cfcc23644f2"
 89                },
 90                "walk": {
 91                    "direction": 0,
 92                    "distance": 139,
 93                    "ename": "",
 94                    "fill": 0,
 95                    "geo": ".=A+\/kLBjzpQPA;|.=QUBlLBw7qQPA;|-=A+\/kLBw7qQPAAAAAsEAg8VBAkBAgAAAAAAAAAAAA05AgAAAAAAAAAAAAkBAgUAAAoAAAgqAgUFAg4BAA5BAgAAAANHAAAAAAsJAAKAAg4QAA;",
 96                    "real": 1,
 97                    "sname": " A\u53e3\u51fa",
 98                    "time": 116,
 99                    "wfi": ""
100                }
101            }
102        ]
103    ]
104}

Using this data I completed the first version of my transit routing app:

While cool (and it was quite fun to decode it, especially geo which is delta encoded BD09 Mercator coordinates) the biggest discovery I made is that Baidu Maps does not send departure and arrival times for buses, metros or trains! The hour the line starts and stops running trains is provided (startTime and endTime) and the duration between stops (time) but not the departure and arrival times themselves. That is unusable for a transit routing app. So I moved onto approach 2: Generating timetable data to ingest into a routing engine.

link MetroMan

During my research I found a popular, english language, transit navigation android app called MetroMan which I thought could provide an alternate route endpoint with departure and arrival times. So I used apk-mitm and a HTTP proxy defined on my phone to investigate the traffic in Charles Proxy. To my surprise I saw only these requests:

  • https://metroman.oss-cn-hangzhou.aliyuncs.com/app/metromanandroid/v202005/version.txt which is a CSV mapping a 2 letter China city code to a date code and a filesize
  • https://metroman.oss-cn-hangzhou.aliyuncs.com/app/metromanandroid/v202005/{city code}/{date code}.zip which contains a number of files

For example Beijing (bj) contains the files:

20260629/
├── beforeholiday.csv
├── BJMW01A.csv
├── BJMW01B.csv
├── BJMW02A.csv
├── BJMW02B.csv
├── BJMW03A.csv
├── BJMW03B.csv
├── ...
├── fare.csv
├── fare1.csv
├── fare2.csv
├── fare3.csv
├── fare4.csv
├── holiday.csv
├── info_cn.csv
├── info_en.csv
├── info_tw.csv
├── lang.csv
├── line.csv
├── link.csv
├── path_latlng.csv
├── path_rail.csv
├── routemap_bj_cn.png
├── routemap_bj_en.png
├── routemap_bj_ja.png
├── routemap_bj_tw.png
├── schedule.csv
├── station.csv
├── transferfrom.csv
├── transferto.csv
├── uno.csv
├── way.csv
├── wayschedule.csv
├── waytrain.csv
└── workday.csv

More proof that this is Beijing is routemap_bj_en.png:

link GTFS

Transit routing engines, like Google Maps or the self hosted OpenTripPlanner, internally ingest primarily “GTFS Schedule” files. So, to use this unknown MetroMan data in OpenTripPlanner for my own transit app I would need to statically compile GTFS zip files. My only source for GTFS feeds became the official specification which is comprehensive and surprisingly readable.

To start I wanted to make the minimal GTFS feed possible. I needed to generate an agency.txt, stops.txt, routes.txt, trips.txt, stop_times.txt, calendar.txt and shapes.txt at minimum to begin generating routes (excluding fares).

link Stitching Together Trips

Starting with BJMW01A.csv from MetroMan, and using the guess that most lines start at 6AM and end between 10PM and midnight (as seen from Baidu Maps), I assumed this likely contained stop time data. The file contains a list of sets of integers (where the second is always greater than the first) that is increasing until it roughly resets again. This repeats a large number of times (for this file around 50).

 1309,313
 2316,320
 3326,330
 4...
 51394,1398
 61401,1405
 71409,1413
 8297,303
 9301,307
10304,310
11...

My first guess was that it represents the departures and arrivals of a particular train i from each of the stations on its route, where for a particular line j in a block the pair represented the departure time of that train from station j and the arrival at station j + 1. The times being represented by the number of minutes since midnight.

I discovered this was not the case. The code I wrote to parse the file like this failed when:

  • A block had more/less lines than stations on the route (in this file the blocks are far larger with 283 at most)
  • A pair is not guaranteed to lie outside a later pair (for example 401,405 followed by 404,408)
  • Sometimes the first pair of a block comes before the first pair of an earlier block. It doesn’t make sense for the file format to allow train i + 1 to have an earlier departure time from its first station than train i

I decided I needed more information. What files contain the strings BJMW01A? The file way.csv contains that string:

1BJMW01A,0,2,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
2BJMW01B,0,2,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
3BJMW02A,1,2,35,36,37,10,38,39,40,41,42,43,16,44,45,46,47,48,49,50,35
4BJMW02B,1,2,35,50,49,48,47,46,45,44,16,43,42,41,40,39,38,10,37,36,35
5...

A clear hint: BJMW01A has a reverse list of numbers, which appear to be indices in another file, compared to BJMW01B. Could this be two routes on the same line in different directions? Another file contains the string BJMW01A, and that is uno.csv. It contains a huge number of lines that appear to indicate names of other IDs:

 1BJMW01A<,>MW<,>To Universal Resort<,>环球度假区方向<,>環球度假區方向<,>ユニバーサル·リゾート方面<,><,><,>0<,>0<,>0<,>0<,>
 2BJMW01B<,>MW<,>To Pingguoyuan<,>苹果园方向<,>蘋果園方向<,>苹果園方面<,><,><,>0<,>0<,>0<,>0<,>
 3BJMW02A<,>MW<,>Outer loop<,>外环<,>外環<,>外回り<,><,><,>0<,>0<,>0<,>0<,>
 4BJMW02B<,>MW<,>Inner loop<,>内环<,>內環<,>内回り<,><,><,>0<,>0<,>0<,>0<,>
 5...
 6BJMS001<,>MS<,>Pingguoyuan<,>苹果园<,>蘋果園<,>苹果園<,>pingguoyuan<,>pgy<,>39.925797<,>116.178387<,>895<,>1588<,>
 7BJMS002<,>MS<,>Gucheng<,>古城<,>古城<,>古城<,>gucheng<,>gc<,>39.907449<,>116.19033<,>895<,>1742<,>
 8BJMS003<,>MS<,>Babaoshan<,>八宝山<,>八寶山<,>八宝山<,>babaoshan<,>bbs<,>39.907416<,>116.235894<,>1091<,>1814<,>
 9BJMS004<,>MS<,>Yuquan Lu<,>玉泉路<,>玉泉路<,>玉泉路<,>yuquanlu<,>yql<,>39.907439<,>116.252884<,>1195<,>1813<,>
10...
11BJMS035<,>MS<,>Universal Resort<,>环球度假区<,>環球度假區<,>ユニバーサル·リゾート<,>huanqiudujiaqu<,>hqdjq<,>39.849145<,>116.679085<,>4057<,>2366<,>
12...

Universal Resort and Pingguoyuan are on opposite sides of Beijing’s line 1. Also, station Pingguoyuan is under ID BJMS001, which is the first station listed in the file. Universal Resort is under ID BJMS035 which is the 35th station. The station IDs start at 0 and end at 34. And, finally, To Universal Resort implies that station is the final station on that route, which is 34. It seemed clear to me way.csv must define the stations on a route defined in uno.csv.

Afterwards I returned to BJMW01A.csv and I noticed a coincidence: the number of blocks in this file was an exact multiple of num stations - 1 on the route in way.csv. Perhaps the file instead indicated the departures from a particular station i, where i is the block index? When I implemented a parser for that data scheme the prior problems disappeared. The primary reason blocks had differing numbers of pairs, and ocasionally had earlier starting pairs than prior blocks, was because a particular route may have trains that start at a station other than the first in the route, or end at a station other than the last. This appears to often happen in the early morning or the late evening, so that someone at a station later in the route doesn’t have a later first train than someone else.

What remains, however, is a harder problem: this scheme encodes departures associated with a station, not with a train like GTFS requires! So I needed a algorithm to connect departures and arrivals with a particular train:

Each pair d,a in a particular block b represents a departure from station b and an arrival at station b + 1 for a particular train. A pair from block b + 1 can be said to have "claimed" a pair from block b if they are adjacent and represent the same train. A pair in block b + 1 is adjacent to a pair in block b if its departure equals the latter’s arrival. If a departure from station b + 1 equals an arrival in block b the unclaimed pair in block b that satisfies that property is claimed. If no pair is found the pair in block b + 1 is assumed to be the start of a new train. After all blocks are processed the arrivals in all unclaimed pairs are added to a train’s route as the final station.

The linking is done by equality because it was assumed that a train was guaranteed to depart at the same minute as it arrived to a station. Once I implemented this algorithm the equality invariant held true.

The final step was determining why BJMW01A.csv contains twice as many blocks as stations. After checking the rest of the files named after routes (or potentially "ways" internally because of the W, but I went with routes) I noticed that the multiple always matched another number: The number of different schedules mentioned in wayschedule.csv. For BJMW01A there are 2: Weekdays and Holidays. This rule did hold, but then I had to figure out what days were assigned what schedules.

1BJMW01A,14810,Weekdays,Holidays
2BJMW01B,12791,Weekdays,Holidays
3BJMW02A,4985,All
4BJMW02B,4980,All

For this I checked schedule.csv, which contains the same schedule type strings like Weekdays and Holidays with 10 bits. I initially assumed that the first 7 bits corresponded to days of the week, and one of the last 3 indicated holdays, and this held. The first 5 bits were always set for weekdays, and the 10th bit was always set for holidays.

1All<,>1<,>1<,>1<,>1<,>1<,>1<,>1<,>1<,>1<,>1<,>Everyday<,>全日<,>全日<,>毎日
2Weekdays<,>1<,>1<,>1<,>1<,>1<,>0<,>0<,>1<,>1<,>0<,>Weekdays<,>工作日<,>平常日<,>平日
3Holidays<,>0<,>0<,>0<,>0<,>0<,>1<,>1<,>0<,>0<,>1<,>Holidays<,>节假日<,>假日<,>土・休日
4Week1234<,>1<,>1<,>1<,>1<,>0<,>0<,>0<,>1<,>0<,>0<,>Weekdays(Mon. to Thu.)<,>工作日(周一至周四)<,>平常日(週一至週四)<,>平日(月~木)
5Week5<,>0<,>0<,>0<,>0<,>1<,>0<,>0<,>0<,>1<,>0<,>Friday<,>周五<,>週五<,>金曜日
6Week6<,>0<,>0<,>0<,>0<,>0<,>1<,>0<,>0<,>0<,>0<,>Saturday<,>周六<,>週六<,>土曜日
7Week7<,>0<,>0<,>0<,>0<,>0<,>0<,>1<,>0<,>0<,>1<,>Sunday & Holidays<,>周日、国定假日<,>週日、國定假日<,>日曜日・祝日

Finally, I needed to determine what days were holidays in MetroMan. Luckily the file holiday.csv is also in the zip. It simply contains days in the year the zip corresponds to:

120260101
220260102
320260103
4...

The holidays in Beijing’s file included:

  • New Year’s Day (Jan 1 to Jan 3)
  • Spring Festival (Feb 15 to Feb 23)
  • Qingming Festival (Apr 4 to Apr 6)
  • Labour Day (May 1 to May 5)
  • Dragon Boat Festival (Jun 19 to Jun 21)
  • Mid-Autumn Festival (Sep 25 to Sep 27)
  • National Day Golden Week (Oct 1 to Oct 7)

The routes were done. From there I was able to determine which line a route follows (line.csv) and the coordinates of a line (path_latlng.csv and path_rail.csv). Those coordinates are encoded in GCJ02 Mercator this time, so I only needed to convert once instead of the twice (BD09 -> GCJ02 -> WGS84) for Baidu Maps.

link Routing Engine

Since the project shifted to compiling GTFS feeds from reverse engineered timetables I needed a routing engine to generate routes between coordinates given departure times. For that I came upon a well supported project called OpenTripPlanner.

The setup was simple: Obtain the OpenTripPlanner jar, build the "graph" from a PBF file describing the supported region and any GTFS schedule zip files with java -Xmx32G -jar otp-shaded-2.8.1.jar --build --save then serve the OTP GraphQL server with java -Xmx15G -jar otp-shaded-2.8.1.jar --load --port 8765 --serve .. For the PBF files I downloaded China and Taiwan then combined them. To prevent ram exhaustion on my machine I employed osmium tags-filter --remove-tags until the resulting PBF file supported transit, and walking between nodes.

After that, I just interfaced with the OpenTripPlanner REST API:

 1POST /otp/transmodel/v3 HTTP/1.1
 2Content-Type: application/json
 3
 4{
 5  "query": "query trip($dateTime: DateTime, $arriveBy: Boolean, $from: Location!, $to: Location!, $walkReluctance: Float, $walkSpeed: Float, $maxAccessEgressDurationForMode: [StreetModeDurationInput!]) {\n  trip(dateTime: $dateTime, arriveBy: $arriveBy, from: $from, to: $to, walkReluctance: $walkReluctance, walkSpeed: $walkSpeed, maxAccessEgressDurationForMode: $maxAccessEgressDurationForMode) {\n    tripPatterns {\n      legs {\n        mode\n        aimedStartTime\n        aimedEndTime\n        expectedStartTime\n        expectedEndTime\n        duration\n        fromPlace { name }\n        toPlace { name }\n        line { publicCode name presentation { colour } }\n        pointsOnLink { points }\n      }\n    }\n  }\n}",
 6  "variables": {
 7    "arriveBy": false,
 8    "dateTime": "2026-12-02T07:30:03Z",
 9    "from": {
10      "coordinates": {
11        "latitude": 39.82612319211683,
12        "longitude": 116.41595932783939
13      }
14    },
15    "maxAccessEgressDurationForMode": [
16      {
17        "duration": "60m",
18        "streetMode": "foot"
19      }
20    ],
21    "to": {
22      "coordinates": {
23        "latitude": 39.842468724545675,
24        "longitude": 116.39089676680423
25      }
26    },
27    "walkReluctance": 1,
28    "walkSpeed": 1.33
29  },
30  "operationName": "trip"
31}

The main variables I tweaked were walkReluctance and maxAccessEgressDurationForMode.duration. The first I decreased from 2 to 1 so that walking and transit are weighed equally, compared only by trip duration. The second controls how long a leg of a particular type is allowed to be before OTP gives up, which I increased for walking. I made both of these changes because I prefer to see those routes when I am travelling as alternative options for sightseeing local areas.

With that I invite you to check out the transit navigation app I made that supports 48 cities across China, representing over 830 routes and 7000 stations.