Line Based Objects
As you may have read in previous posts – a lot of the objects in open street map are represented as polygons, however, many other objects are represented as polylines. A polyline is simply a collection of points which together represent straight line segments. When chained together these line segments work together to represent the path of an object on the map. In the case of the data we have requested – a road, river/stream or a railway line.
Identifying Polylines
The first step to being able to render these is to distinguish between polylines and polygons. Previously I was having some trouble with certain “polygons” not triangulating correctly so I had temporarily removed these types from my web request. I have now realised it was just that some river sections were represented as polygons while others were represented as polylines. If you triangulate a polygon it looks good – if you try to triangulate a polyline it looks… well the exaggerated results show below speak for themselves!
To distinguish between Polygons and polylines I was initially checking for the “area=yes” in the object tags. As described here: osm wiki this will not always give the desired results. Sometimes “area=yes” is implied by the object type/other tags and in other cases the opposite is true. It seems that the easiest way to distinguish between polylines and polygons is to simply look at the raw coordinate data. If the first coordinate and last in the list are the same, the object is a closed polygon, otherwise assume it is a polyline.
Rendering Polylines
To render these, I simply looped through the polyline points, generated vertices formatted as a GL_LINE and submitted the primitives to OpenGL. The gallery below shows what the lines look like, the polygon elements look like and then finally both combined. Incase you are wondering – the red lines represent railway tracks!
It is not recommended that we draw using line based primitives. Some of these reasons are due to performance and compatibility issues. A better visual will be also achieved if these are drawn using triangles anyway. Stay tuned for next time where I will try to work out how to parse the width for the line elements and then use these to generate triangles.
Video!
You can also see a video of the renderer including these lines by clicking here: OSM Video.
1 thought on “OSM Renderer – Polylines part 1”