2

I am rendering data from OSM. There are various styles for different features(city road, highway, country road, walking path..). In order for a highway to be rendered above a simple road, it has to be rendered last, otherwise the roads would look like they lay above the highway. Of course this applies in general to all objects, not just roads.

So I wonder how can I determine the proper order? Using the area of the feature usually works for polygons, but even then not always. The OSM has a gazzilion of tags so trying to figure this out via trial and error would take ages. I'm sure there is some guideline or prepared set of rules for this somewhere but I haven't found it yet.

1

As to highways specifically, the most common way to render them at large scales (1:1 to +/- 1:50k) is to use the OSM 'layer' key (https://wiki.openstreetmap.org/wiki/Key:layer). Layer defines the relative vertical position of crossing but unconnected highway elements, e.g. a secondary road viaduct over a motorway, or motorway flyovers at a major highway junction. Valid Wiki documented values are -5 to +5, and should cater for even the most exotic highway junction. However, sometimes people falsely use values outside this range, e.g. as a substitute for the OSM 'level' key (https://wiki.openstreetmap.org/wiki/Key:level). This is wrong, but you should reckon with this fact and deal with it. I usually default values outside the range to the maximum values. E.g. a false value of 'layer=11' is set to 'layer=5' in code.

As to the stacking of all other features: except for the already mentioned tip of reviewing some of the existing styles, which should give you a basis to work from, there is no substitute for "old fashioned" cartography... If you're unwilling to invest time in styling and cartography, then you should really reconsider your choice of OSM as datasource for your mapping needs, and maybe get some commercial or government sourced datasets with pre-configured layering and styling.

  • That's actually an answer to a different question, I think - "layer" is used for "what things in the physical world are above or below other things". What I think the questioner is asking is "when e.g. a road goes through a forest, how do I make sure the road is visible over the firest". – SomeoneElse Mar 6 at 14:52
0

You can sort lines in the order of importance but as you can see through the data, things doesn't always mantain the same logic.

For example, using the same downloaded data you will find this (correct order of elements): enter image description here

...or this (lower and secondary road over the highway): enter image description here

So, what I can figure it out from your post is that you need to stablish an order of importance of roads and show the main ones over the secondary ones. In this case, highways always over the others, independently from the aerial view.

You can do that in two steps:

  1. Create a new attribute that defines the order or importance of the road (you decide your order):

enter image description here

  1. Sort (using MMQGIS for instance) by that new attribute.

enter image description here enter image description here

Now if you apply the same style to this new sorted layers you will get those highways always on top (even if It is not the real aerial view...): enter image description here enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.