User:Stanton/OSM Transport Map

From OpenStreetMap Wiki
Jump to navigation Jump to search
Early prototype of a transport map on OSM as described below (rendering style has been changed since)

Many public transport companies already offer city maps with bus, tram, metro and other lines superimposed on them. OSM has all the necessary data to offer a similar view - with world-wide coverage, using the same familiar layout wherever you go, and free for anyone to use, copy and modify. This page is the central repository for a project to integrate just this functionality into the main OSM page.


Add another map layer and overlays to represent public transportation lines to the main OSM page. Where possible, reuse OSM infrastructure and make standard OSM tools (namefinder, export) available. The solution should be "grandma-proof", i.e. it should be simple enough so you can tell your grandmother (or any other non-techie of your choice) to "go look up your bus connection on OSM" without confusing her.


Many public transport companies already offer city maps with bus, tram, metro and other lines drawn on top of them - but with the usual copyright restrictions, and each company has their own layout.

The big commercial player in the field shows clickable stops on their (non-free) map, which will return the lines serving it, but there is no way to show the route of a line. Their transit platform still does not cover many cities (e.g. Munich, Milan). In Milan, bus stops are missing completely on the map, the location of subway stops is approximate at best and the network data seems to be out of date. We can surely do better than that - steps 1 to 2a (see below) would already put us ahead of them.

OSM already has the raw data needed to offer a free replacement for all of the above, and some efforts have been made already. However, they all have some restrictions:

  • Some are non-free (the map data is, but the platform is not open-source).
  • They all lag behind in updates as they get updates from OSM only once in 24 hours or even less.
  • Coverage is partial, often limited to a metropolitan area or single country.
  • The biggest player in the field, Öpnvkarte, is currently unmaintained.
  • Use is often limited to viewing, other OSM tools, such as Nominatim and map export, are not available.

In short, we have a handful of "islands", and even though some of them have quite nifty solutions, there is no "definitive" site yet.

Having such a map as another map view on the main OSM page would give us some advantages:

  • Easy switching between "normal" and "public transport" view: this would be just a matter of switching base layers. Imagine getting the name of a pub, looking it up on OSM and then switching to the Public Transport map view to see nearby tram/bus lines and the nearest stop.
  • Only one URL to remember
  • Uses most recent data if run off the GIS database on yevaud, the same one used to render the default Mapnik view
  • Standard OSM tools available: for instance, Nominatim and map export in various formats
  • Could be a "killer app" for OSM: OSM would be the first to offer this information for the whole world in a single standardized format. It looks the same in every city, which helps those who travel frequently between cities.
  • Encourages public transportation mappers: Newly-mapped lines are visible almost instantly, an intuitive sign for mappers that they got their tagging right. At the same time, it increases the awareness of such data being available on OSM (new users who "explore" the site are quite likely to come across it) and will likely result in more people using and improving the data set.

Similar efforts

Several sites already provide public transportation maps with some good approaches (which we should learn from) but also some drawbacks or limitations (where we should do better).


Öpnvkarte is not getting any updates at the moment; the maintainer explained in a post to talk-de:

The problem is that the server can't handle the data load any more. Since currently I've reduced my effort on OSM, I haven't really gotten around to fixing it yet.


  • Uses a (mostly) grayscale background, thus road network information remains legible but stays in the background
  • Adjacent stops (poles) are grouped together if they have the same name
  • Additional information: click on stop opens popup with lines serving this stop (or any stop in the group); click on line opens list of stops
  • Popup distinguishes between "services at this pole/stop position" and "services at this stop (group)"
  • Date of OSM data is shown on page (up to September, updates would make it into the database within 48 hours at most)


  • Coverage is limited to Europe (Canarian Islands not included)
  • Stylesheet has some bugs (junctions do not render) and is focused on Germany (e.g. German-style shield symbolizers for highways)
  • Limited to one single map layer
  • Line colors may need some tweaking (bright green for light railways is hard to make out)
  • Popup layout looks a little crude
  • Rendered map cannot be exported Public Transport offers a public transport layer but in fall 2010 reduced coverage to Russia and some neighboring countries (before it also covered at least Western Europe).


  • Familiar Mapnik background layer
  • Lines are implemented as separate layer (overlay), allowing for them to be combined with any base map layer


  • Coverage is limited to Russia and some neighboring countries
  • Background is the standard Mapnik view - map features are too prominent and PT lines do not stand out
  • Some routes (e.g. trolleybus) are not rendered
  • No detailed stop/line information (functionality is limited to map overlay)
  • Rendered map cannot be exported



  • Worldwide coverage
  • Familiar Mapnik background layer
  • Different background layers available (Mapnik or Osmarender)
  • Additional information: click on stop opens popup with lines serving this stop; the layout is a bit nicer than with Öpnvkarte (line colors shown)


  • Not open-source
  • Slow to load
  • Background is the standard Mapnik (or Osmarender) view but dimmed - road network details are difficult to make out and road names are difficult to read
  • OSM data seems several weeks old (the age of the data is not visible anywhere)
  • Uses colors from colour=* tag (or defaults to black) - the type of line (bus, tram etc.) is hard to distinguish; can get confusing in large networks
  • Stop popups show only the pole which was clicked, not other poles of the same stop
  • No detailed line information (list of stops)
  • Rendered map cannot be exported


Openptmap was created in response to Öpnvkarte not being updated any more. It is intended for quick verification but not as a full replacement for Öpnvkarte. It runs on limited hardware, thus functionality is limited.


  • Detailed setup instructions available on Wiki page
  • Choice between different map backgrounds (Mapnik or OpenCycleMap, standard or dimmed)
  • Map background can be switched off altogether (renders only lines on white background)


  • Background is either a standard or a dimmed map view, with the problems mentioned for the other renderers
  • Line colors may need some tweaking (tram and ferry are almost the same color)
  • Updates may take up to 10 days to appear on the map
  • Coverage is limited to German-speaking area
  • No detailed stop/line information (functionality is limited to map overlay)
  • Rendered map cannot be exported

OSM Inspector

OSM Inspector is intended as a debug tool, not for looking up information on a map. It offers a Public Transport background layer, which uses tiles from Öpnvkarte.


OpenStreetBrowser is a feature-rich map UI which, among others, offers a public transport layer.


  • Single routes can be highlighted
  • Choice between different map backgrounds (OSB, OSM Mapnik, Osmarender, CycleMap)


  • Background is a standard map view - map features are too prominent and PT lines do not stand out
  • In order to highlight a route, you have to select it from a tree in the left pane (a tedious chore for large networks) - it would be more user-friendly to highlight a route by clicking on it/hovering the mouse over it/selecting it in a stop popup (note that OSB doesn't have these)
  • OSM data appears to be several months old
  • Information when clicking a stop is very technical, not really "task-driven"
  • Coverage is limited to Europe
  • Rendered map cannot be exported


Following the iterative approach with which OSM was and is being built, here's how it could be implemented:

Step 1: Add the new map view

Create a new Mapnik style sheet. Main principles:

  • Start out from the default Mapnik view. Most users should already be familiar with this.
  • Convert most objects to grayscale. Names on a grayscale map are still legible (better than dimmed colors), but the map stays in the background without distracting too much from transport routes.
  • Some items should remain in color: Mostly waterbodies, possibly some landuses (particularly those for areas which tend not to be covered by public transportation routes). In case of conflict, consider reducing color saturation, making colors appear a little pale/grayish so they are visible for orientation but do not distract from the actual purpose of the map.
  • Reduce POIs. Users who need POI information can always switch between map views. Details on what to keep and what to drop will probably need to be discussed, though.
    • Keep POIs which tend to be of particular interest to public transport users (e.g. park-and-ride parking lots, taxi stands, bicycle rental stations)
    • Drop POIs which are of little interest to public transport users (e.g. gas stations).
    • Low-density POIs, commonly found at most once or twice per town or city district (schools, universities), can be kept.
    • High-density POIs (e.g. bars, shops) should be omitted.
    • POIs of particular importance (e.g. police stations, hospitals) are probably worthwhile keeping if their density allows it.
    • Move stops and stations to the transport layer (with special rendering)

Display routes and numbers in color on top of the map, preferably as a separate layer (this allows us to reuse the black-and-white background for future applications and gives us some extra flexibility in Step 2a).

Already there

  • The database
  • The rendering infrastructure
  • The current Mapnik stylesheet


  • A second Mapnik style sheet for the background (basically an adaptation of the current one)
    • Prototype exists, auto-generated from the current live style sheet (which needs some minor modifications, namely splitting up some styles)
  • Another Mapnik style sheet for the route overlay (if we decide to to it that way)
    • Rough prototype exists, thanks to Marqqs
  • Possibly some post-processing of OSM data in order to render the routes
    • Basic route rendering is possible without post-processing
    • Grouping lines (for labeling ways with one list) is possible by defining a new aggregate function for PostGIS requires relation information to be imported in PostGIS - see ticket 3490
for osm2pgsql
    • Direction arrows on routes: would be possible if relation information is available, see above
  • Group nearby stops based on same name and proximity
    • Perfect solution requires complex algorithms (cluster analysis)
    • Simpler approaches are possible, based on distance. This post mentions 150 m for a pair of stops, 250 m for a cluster.
  • Running Mapnik with two different styles (Cloudmade and Wikimedia Toolserver already do that)
    • Mapnik can run with any number of styles; details depend on how tiles are rendered. The OSM platform uses mod_tile, which should support multiple directories with different styles for each.
  • Some hacking to the export feature so that exporting the Public Transport view will export the combination of map background and PT overlay
    • Possibilities are either a third Mapnik style which contains all layers of the background and overlay styles (maybe generated automatically from the original style sheets), or rendering two maps and combining the images.

Step 2: Add stop information

Add a new overlay, which makes all stops clickable. Clicking on a stop opens a popup bubble with information on it, such as name and lines stopping there.

Crude example:

Services at Lampugnano
M1 Rho Fiera - Sesto San Giovanni highlight | sketch
68 Bus.png Bonola - Via Bergognone highlight | sketch

Already there

  • OpenStreetBugs (and some other sites) already have overlays with points that open a bubble when clicked.
  • Öpnvkarte groups nearby stops belonging together (take Munich's central station, which consists of one light railway stop, two subway stops, three tram stops and a couple of bus stops): that way the user just needs to click the station and gets a popup with all the light railway, subway, tram and bus lines.


  • Some extra code for the popups (though not really new)
  • Probably some extra post-processing on the data in order to group nearby stops together

Step 2a: Route Information

In the popup for each stop, links or icons next to each service are available to:

  • Draw the course of the service on the map (hiding all other services)
  • Open a new window with a sketch of the route.

Already there

  • Sketch Line from OSM Server Side Script, example already does an excellent job at this; certain output aspects can be customized with style sheets
  • OpenLayers already supports adding an extra layer using raw XML data as its input; this can be done for relations (whose data is downloaded directly from the API)


  • Integrate Sketch Line into main OSM Platform
  • Create a universal style sheet
  • Tweak Sketch Line's choice of colors: Currently they seem to be chosen semi-randomly, better options would be:
    • Use the color scheme of the main overlay (one color for each type of transport)
    • Use line colors if specified in relation, black otherwise
  • Output may need to be converted into a bitmap on the fly (Sketch Line produces SVG output, which not all browsers out in the field handle well - especially those used by non-geeks do not support SVG).
  • If traffic gets high, we may consider caching the line sketch graphics (optional).
  • Add OpenLayers logic for switching from "all routes" to "single route" overlay and back - should be fairly easy
  • Add some beauty to single route overlay (preferably same line style as in "all routes" overlay)

Step 3: Extensions

Up to the imagination of the community:

  • Some kind of collaboration with transiki (OSM provides lines and routes, transiki provides timetables)
  • If one day we add routing to the OSM page, we could extend that to finding a public transport connection

Detailed Steps

  • Spread the word to Transiki - our work might be interesting for them as well, and we might attract some more people to work on this.
  • Open a ticket with a feature request for Mapnik (second stylesheet)
  • Contact Melchior Moos (maintainer of Öpnvkarte) to see if he is willing to open up his code
    • I contacted him and got his code for generating the map. However, his code is of limited help as he does not use osm2pgsql but a homebrew utility to fill the PostGIS database, resulting in a different database scheme from the one on the OSM server. While he has done good work, it also means that I'll have to take a different road in order to remain compatible with "any standard Mapnik server".


Color Scheme

The color scheme resulted from collaboration with Ieskok, studying of topographic transport maps in several European cities and attempting to use the predominant colors as far as possible.

Color Description Tag
#000000 Railway route route=train, route=railway
#197419 Light rail route route=light_rail
#3232e8 Subway route route=subway
#e88d32 Tram route route=tram
#e83232 Trolleybus route route=trolleybus
#191974 Bus route route=bus
#741974 Share taxi route=share_taxi
#32afe8 Ferry route route=ferry


References, Manuals and Sample Code

OSM Platform (live and dev)