1

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">
    <union>
        <query type="way">
            <has-kv k="piste:type" v="nordic"/>
        </query>
        <query type="relation">
            <has-kv k="piste:type" v="nordic"/>
        </query>
    </union>
    <union>
        <item/>
        <recurse type="down"/>
    </union>
    <print mode="body"/>
</osm-script>

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?

2
  • 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, 2019 at 15:05
  • You should be able to use an aggregate() expression to do this, since it allows you to reference another layer. See youtu.be/IXPCec8vgLA Aug 12, 2020 at 20:08

2 Answers 2

1

From askers comment:

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.

1

Plugin refFunctions 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

For example try geomcontains():

Retrieve target field value when source feature contains target feature in target layer

1
  • 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, 2019 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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