Mapping Nairobi’s Matatu Routes

About 70% of Nairobi’s population uses matatus and buses to commute between home and work. Despite this, information on matatu/bus routes and stops remained scarce until the Digital Matatus project collected the field data in 2014. Let’s take a closer look at their GIS data and see whether we can put it to good use.

The Data

The Digital Matatus project was conceived out of collaboration between Kenyan and American universities and the technology sector in Nairobi. It has collected public transit data, developed mobile routing applications, and designed a transit map for Nairobi city.

The GPS data for routes and stops was collected by student teams from the University of Nairobi. They rode matatu routes and collected data using mobile devices, personal observations, and discussions with commuters and operators. The Map section of the Digital Matatus website provides access to the final data products and has a download link for the GIS data. I performed a data quality review and noted the following:

  • Accessibility – The GIS data can only be downloaded as an ArcGIS file geodatabase. It can’t be previewed or downloaded in an open standard file format. This restricts data access to those with software that can import file geodatabases.
  • Completeness – The datasets record a total of 133 matatu routes and 2481 matatu stops. In the absence of other verifiable data sources, we can assume that the project has captured most if not all of Nairobi’s matatu routes and stops.
  • Attributes – The route attributes include a route identifier (e.g. 46K), a description (e.g. Kencom-Valley Road-Yaya Centre-Kawangware) and origin and destination. This adequately describes the route when one understands that the route reverses from its destination to its origin. The stop attributes include a unique stop identifier, a stop name, a parent station, a lat/long coordinate pair and a total of 21 attributes to identify the route that passes through the stop. Stop names aren’t always informative and at times duplicated, and the concept of parent stations remains unclear. Modeling a many-to- many relationship with 21 attributes is clumsy to say the least and a junction table containing the route and stop identifiers should have been used instead.
  • Accuracy – Since data was collected with a Smartphone when riding the matatu, the horizontal accuracy of the spatial data could be in the range of 5 to 10 meters. This is acceptable for many navigation and routing applications. A bigger challenge with the spatial data is the lack of conflation, meaning that routes or route parts that are logically coincident have not been merged. Data looks fine at small scale, but at larger scales routes appear as a tangle of lines, while a single station appears as a multitude of stops.
  • Topology – The lack of coincidence between matatu routes is a topological error that can be addressed by aligning the matatu routes to a common road reference like OpenStreetMap. The stops are difficult to use in a topology, since they are just too many and can’t easily be linked to the origin or destination of a matatu route. Matatu stops from Google Maps could be used as a substitute, but gleaning the coordinates and route identifiers will be a tedious exercise.
  • Relevance – The Digital Matatus projects has succeeded in documenting the semi-formal matatu routes in Nairobi and the pocket and wall map that it has delivered are useful information products. The GTFS data could support certain urban applications, but the poor structure of the GIS data makes it unsuitable for trip planning and multi-modal routing.

Data Preparation

The initial project goal was to develop a trip planner that tells one which matatu(s) to take to get from A to B. To build network connectivity, participating features first need to be made coincident. I tried to achieve this with a geodatabase topology and started correcting the topology errors, only to realize that the corrected data would not align with any common basemap. A decision was thus made to use roads data from OpenStreetMap (OSM) as a standard reference for the matatu routes.

OSM is a collaborative project that develops an editable map of the world available under a free license. It’s a good data source when proprietary data isn’t an option for financial or technical reasons. OSM data can be downloaded for entire continents, countries, and selected cities, but I opted to download a rectangular study area from BBBike.org.

The OSM data for Nairobi was delivered as a collection of 17 zipped shapefiles. These vector layers compose a complete basemap, but I only needed the roads dataset. I found out that newly constructed roads and some minor roads are missing from the OSM data, but the data appears accurate and perfectly aligns with the OSM basemap in ArcGIS Pro. I was pleased with the oneway and bridge attributes, since they can model one-way restrictions and identify non-level crossings.

Referencing all the 133 matatu routes to the OSM roads in ArcGIS Pro took a couple of weeks, but I it got me acquainted with the editing capabilities of ArcGIS Pro and the different matatu routes in Nairobi. Figuring out the correct alignment of a matatu route was at times a puzzle due to newly constructed roads and newly imposed one-way and turn restrictions, but that made the work engaging.

The workflow that I used eventually became efficient, consistent, and repeatable and was captured as an ArcGIS Pro Task. The finer details of the workflow can be found in an earlier How to Start Using ArcGIS Pro Tasks article, but conceptually there are two main parts:

  • Display a single matatu route, for example 46K, and figure out where is starts, where is passes, and where it ends to return. Matatu route 46K for examples starts at Kencom House, passes through Kenyatta Avenue, Valley Road, Argwings Kodhek and stops and reverses at the end of Gitanga Road.
  • Select all the segments from the OSM roads layer that make up the matatu route and paste them into the layer of the OSM referenced matatu routes. Then edit the geometry and the attributes of the new route so that it accurately models the matatu route.

Following this workflow, all 133 matatu routes contained in the Digital Matatus dataset were referenced to the OSM roads. The new dataset contains 1131 features, since a route is split when the one-way attribute changes. Each feature has route id, route name, one-way (true/false), origin and destination as descriptive attributes. As a final step in ArcGIS Pro the data was published to ArcGIS Online as a hosted feature layer.

Map Visualization

The ArcGIS Online Map Viewer was used to create a Web Map with matatu routes as the only layer. The pop-up window was configured to show the route id, route name, origin, and destination. A Web App was then created from the Web Map with the embedded edition of Web AppBuilder for ArcGIS.

Web AppBuilder for ArcGIS is an intuitive WYSIWYG application with which you can build powerful 2D and 3D web applications without writing a single line of code. You can change the look and feel of the app through configurable themes and the functionality of the app can be configured through a growing list of easy-to-use widgets. As a developer you can even build your own customized widgets.

I used Web AppBuilder for ArcGIS for the first time and don’t consider myself an expert yet, but here are the configuration steps I went through to build my Web App.

  • The first tab you see when creating or editing a web app is the Theme tab. This tab allows you to pick a theme, style, and layout from a wide range of choices. I didn’t pay too much consideration to the options and went with the Foldable theme, a gray style and a layout that places my widget in a prime spot.
  • Next up is the Map tab from where you choose the web map for your app. I simply stayed with the web map that had matatu routes as its only layer.
  • The next tab is the Widget tab where you add, remove, and configure widgets that control the functionality of your app. The default widgets are part of the theme and include off-panel widgets (e.g. Home, Zoom) and in-panel widgets to support common functions (e.g. Legend). Finally, there is a section where you can add your custom widget, and this is where I added and configured the Find Route widget for my application.
  • The last tab is the Attribute tab, where you can add your logo and title, sub-title, and custom URL.

In my application the most difficult part was configuring the custom widget. I used the Query widget and, edited a few descriptions, ticked an Ask for Values box, and ensured that the values in the dropdown list are Unique. It wasn’t that difficult, but it took some time to figure things out.

Enough talk, so take some time to interact with the web app which has been embedded below. I trust you’ll manage to use the Find Route button to locate a certain matatu route.

Use Cases

I spent considerable time building a Web App that only allows you to locate a matatu route in Nairobi. Anyway, the app could form the basis for a Matatu trip finder that will wow everyone in town. To build the trip finder I only need to validate the matatu routes and add accurate information on the stops. Please get in touch if you can help or have an interest.

A total of 133 bus/matatu routes in Narobi is a fair number, but I really wonder whether the routes are being designed in a manner that matches supply and demand. I have observed that Nairobi is expanding towards the East and Northeast, but doubt whether matatu routes have increased in those areas. With the current data on routes it should be much easier to plan for new routes.

Though the number of matatu stops could be overestimated in the Digital Matatus dataset, it appears that Nairobi has far too many matatu stops. Some areas of the city are littered with stops and there are routes where matatus stop after every 100 meters. With the current data on stops it should be possible to confine stops to designated areas that have the required infrastructure.

Recent attempts to ban matatus from Nairobi’s CBD have met fierce opposition from the operators who fear a negative impact on their business. Accurate information on the existing routes and stops combined with accurate traffic data and dynamic transportation modeling could be used to find a solution that merges the interest of all stakeholders.

Wrapping Up

GIS data on matatu roads on stops from Digital Matatus has quality issues that make it unsuitable for trip planning or routing applications. Still locational data on matatu routes and stops remains an invaluable resource for urban planning and design that ought to be put to greater use.

The Nairobi Matatu Road Finder is a basic web app that allows any member of the public to locate a matatu route in Nairobi. The application can be used to validate and improve the current data and could ultimately result in a public transit trip planner.

To facilitate the development of advanced transportation applications it is imperative that transportation data with correct network topology is made available. Data that only looks good on paper is likely to remain on paper.

About Author:

Willy Simons came to Kenya from The Netherlands in 1994. He is a serial entrepreneur and co-founder of Oakar Services, Esri Eastern Africa and Spatiality. He blogs about business, geospatial technology and cloud computing.