Rendering Road Intersections

I have been working on my Master Thesis which is a 3D City Generator taking OSM xml data as input. I am having problems while trying to render road intersections. There are bunch of different conditions for intersections and I wonder if there is an existing library or algorithm for drawing all possible different cases. I try to handle as much as I can but there is always some weird intersections as in the example image below that my code cannot handle :

Btw, my project is open source and you can access by the following link, there exist also several screenshots to show capabilities of my project
https://bitbucket.org/CagkanToptas/polimi-osm-city-engine-unity3d/

Good job, your screenshots look awesome! Can you post a link to the same intersection in OSM? Do you currently have any intersection related code or simply draw road textures?

Here is the image of place from OSM map : (http://www.openstreetmap.org/#map=18/45.80201/9.08500&layers=Q)

What I did till now is to handle all 2 and 3 highway intersections and some cases of 4 way intersections.

  • 2 highway intersection was not difficult. I applied simple vector geometry and link the two road

  • 3 highway was a bit complicated. There are 2 main case in this situation.
    1. 2 different roads, one of them intersect from a middle node
    2. 3 different roads, all of them intersect either from end/start

  • 4 highway even has more conditions like
    1. 2 different roads, both intersect from a middle node
    2. 3 different roads, one of them intersect from a middle node others from end/start
    3. 4 different roads, all of them intersect either from end/start

The image I posted has 5 intersection which consist of 4 different roads, 1 of them intersect from a middle node and others intersect from the end/start

Because of this, I started to think probably there will be cases in somewhere around world which there is even more than 5 intersection at a time. So my question is actually how Openstreetmap render the highways in their tiles from Xml file ? Is the source code available?

Basically, an intersection is just an asphalt area without lane markings. Quick and dirty way to do that is leave your roads as they are, then build a new polygon covering the intersection area, and give it asphalt texture without white lines.

This should work for any number of roads.

OSM uses Mapnik for 2d tile rendering:
http://wiki.openstreetmap.org/wiki/Mapnik
http://github.com/mapnik/mapnik

I had exactly the same issue in my project (see topic I created). I developed solution proposed by shrddr, but my implementation had bugs and wasn’t performance optimized. Finally, I made roads to be part of terrain mesh

There is also a proposal to map the intersections by hand, instead of computing their shapes at rendering stage: http://wiki.openstreetmap.org/wiki/Proposed_features/Street_area