Introducing GPX shapefiles to draw bus routes

by multimob — written on 2024-08-13


Adding route relations to OSM is an obvious requirement. Maintaining them is even more difficult, but that is another problem. How practical is it to add a bus route to OSM?

So far, our home-made generator (DLgen) can work on processed GTFS data and create XML files with route relations containing all the tags and all the stops in the correct order. Those relations can be immediately opened in JOSM and uploaded. This works perfectly now. The only problem is that those route relations only contain stops but not the roads. A route relation without the roads in invalid. And the Transport Layer will be empty, this is not what we want.

Transport Layer where the stops are there but routes connecting them are missing

Adding ways to a relation is by far the most time-consuming task.

Up to now, we use our own shape viewer, which uses the LeafletJS library and which draws the itinerary on top of the osm-carto basemap. By switching from one view to the other we can follow the itinerary and download ways in JOSM accordingly before adding them to the route relations.

We are testing a new system, directly integrated to the online shape viewer. The same query that is used to identify all the data points along an itinerary—which serves to draw the route in LeafletJS—is re-used to generate a GPX text file and offer it for download. We followed the example GPX file on the OpenStreetMap wiki to generate a valid GPX file containing the itinerary.

The advantage of this file is that it can be opened in JOSM, as a separate layer, so we no longer have to switch from one window to the other.

An auto-generated GPX shape

A second advantage is that GPX traces contain timestamps for each data point. By starting the itinerary on a given time of the day and incrementing the timestamp for every point along the itinerary, we can tell JOSM the direction of travel. This will solve a problem we had with our shape viewer: some itineraries make round-trips around a neighbourhood or complicated loops that come several times though the same point. Unless one-way streets or the order of stops make it obvious, there are many cases where the shape viewer is insufficient and the direction of travel is impossible to guess.

JOSM has a built-in feature to render GPX traces with a colour system. Green means that buses go to the east, red means to the west, yellow means to the north and blue means to the south. Colours will be combined for NW, NE, SW and SE directions.

A GPX shape where every segments automatically gets a colour based on its angle

The pt-assistant plugin of JOSM is also a considerable help to highlight route relations. It also runs its own layer. A clever hack is to download a relation, highlight it in the pt-assistant plugin, hide the data layer and compare the two remaining layers.

Showing the GPX shape and the current itinerary in OSM shows a discrepancy

On the picture below, we can see an obvious discrepancy. As always, we should never assume that OSM data must absolutely be changed to reflect GTFS data. But it gives an immediate hint about a potential location to investigate.

And in some cases we can achieve a perfect correlation between GTFS data and the itinerary in OSM. The picture below shows the situation after the itinerary was corrected on OSM.

The GPX shape and the current itinerary in OSM match perfectly now

Can way assignment be automated?

There are probably additional methods to fill ways in route relations.

We identified two possible scenarios.

  1. Download all the ways within a corridor around the GPX shape, then identify ways where the geometry matches this data most closely. The main challenge is that OSM nodes that make up the ways are not the same as all the track points in the GPX file.
  2. Run an navigation query, possibly with a "bus" profile (granting access to busways, service roads and pedestrian areas), extract the ways from the result, and calculate a score to see how that geometry matches the GPX file. Give more weight to roads that already have bus route relations. This query should not be calculated on the whole line at once but for small consecutive segments.

We have no plans to develop it ourselves in the near future, but we are happy to assist students or researchers who would like to explore this.


Permalink: https://blog.multimob.be/zzaereLae7.htm

Back to the index

Screenshots with maps are © OpenStreetMap contributors