How to add live traffic data layer to OSM ?


I’m working on an application to display live road traffic data.
Now i have an app running on WinMobile that logs points (lat, long, time) and then sends the log to a server.
After that I want to process all that data (comming from different “probes” - devices) and display the average speed on a road segment.
As map i would like to use OSM because of its openess :slight_smile:

So, my question is: how can i add a layer on osm that will display this caracteristics ? For example i would like to display some lines over the roads, colored depending on the average speed. What sould i do ?

Thanks and i hope to succed :slight_smile:


There’s a small chance JRA might say something about this…

Anyways; do you want to render the speed on every road? How often will the data change and how many users will you have…

If you want to do all of the roads the “easiest” would be to render your own PNG tiles (which is done with e.g. mapnik) and add them on top of openstreetmap javascript map (which is done with open layers). Then add a tag to each way with avarage_speed=50 and modify a mapnik rule to render that.

If you just want some roads, under 30, then you could use open layers and draw vectors ontop of the map. This is probably hard… :slight_smile: But might be easier for you todo since you don’t have to setup a server.

Well using OpenLayers you can load the speed data as vectors into a layer. This can be done for instance by converting all the speed data into KML and add different color styles to the sections for the different speeds. Use a GML parser to load the KML into OL. An example of this is my routable Garmin maps website. In this case the road sections are squares and the only color style is the red one (the blue is the default style), but in general it’s the same as your application. Just have a look at the javascript source code and KML file.

I found actually something to that direction from last November but then I was playing just with static map background (local ecw image) and GIS program reading vector data on top of the base map from PostGIS through Web Feature Service (WFS).

Unfortunately I am not an expert in making map applications to the web. However, it would be refreshing to see sometimes also other techniques used that just OpenLayers. For this kind of need perhaps an old fashioned server side system that combines the base map and real time traffic info as a separeare layer could be just fine. Something in the style of Mapbender application at
Play with “Verkehr” - “Buslinien” and imagine that they present your speed data.

It’s very easy to create an overlay like the mapbender one, you could basically just use any of the renderers, create transparent pngs, and do some more hacking.

Perhaps pre-rendered tiles are not as their best in this usage. I suppose that traffic data is live and therefore there will be nothing that could be kept in cache. But perhaps a transparent WMS layer showing classified traffic data directly from database on top of tiled base map, of even WFS layer. With WFS if would be possible to deliver attribute data as well and make application queryable (time of the last update, average speed in exact numbers, number of vehicles, max and min speeds etc). Unfortunately Openlayers is rather slow with WFS vector data.
I am sorry if I feel contaminated by GIS and OGC web services, but they are what I am working with.

I’m experimenting with setting up a service usable of OSM-routers (first of all of cause my own one).
I’m currently getting traffic data only via TMC from local receiver while driving.

The schema for storing my traffic-messages is documented here:
It is still incomplete, so if you have any usefull comments, feel free to comment. :slight_smile:

Update: I added a class-diagram and some lines of text to make it easier to understand what I’m trying to do there.


The first code for the server is not in SVN:


On somehow the same problem asked, I would like to add a vector layer on top of OSM basemap. What technology do you suggest? I am thinking of creating KML files and loading it on top of OSM. any better suggestions? or better if you provide a link to an article… :slight_smile: Thanks!

Dear Lambertus,
I have the same problem, and think you answer would help me. but I cannot see the javascript source code and KML file that you’re refering to. would you please provide a link? Thank! :slight_smile:


Did you find a solution to your problem? Please share it in here. Thank you :slight_smile: