A brief overview of what I want to achieve: Create a map showing all cross-country ski trails in a specific region with some customizations/styling on them.

The data come from OpenStreetMap exclusively. Ski trails can be either relations or ways.

I imported the ways and relations from OpenStreetMap using QuickOSM plugin in QGIS 3 with the following Overpass query:

<osm-script output="xml" timeout="25">
        <query type="way">
            <has-kv k="piste:type" v="nordic"/>
        <query type="relation">
            <has-kv k="piste:type" v="nordic"/>
        <recurse type="down"/>
    <print mode="body"/>

Now I have 2 layers in QGIS, one for lines (OSM ways) and one for multiline strings (OSM relations).

What I want to do is to add a label on ways (showing the value of the attribute piste:name or, if it doesn't exist, name) only if those ways are not part of a relation from the second layer. This is to avoid duplicating the label since these relations already have their name displayed with another labeling rule.

I tried to write rules using geometry functions like contains() but it seems that I can't reference an object from another layer.

Is there a way to achieve what I want to do in QGIS?

  • I finally found a workaround to my issue. Instead of trying to test if a way is a member of a relation inside QGIS, I ran an additional Overpass API request to fetch ways that aren't par of any relation. Thus I now have a third layer with those ways, on which I can apply a simple labeling rule. – Romain Apr 23 '19 at 15:05

Plugin refFunctiond will allow You to interact with geometry from another layer.

From the description:

Plugin that add custom user functions to Qgis Field calculator for referencing, analitically or spatially, between layers, For example retrieving a value from a layer using as a field value or a spatial condition (intersects, disjoint ....) as parameter

| improve this answer | |
  • Thanks for your suggestion, but the plugin didn't help me that much since I had to test the geometry against each object of the layer. I added a workaround to my issue as a comment to my question. – Romain Apr 23 '19 at 15:09

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.