I have several layers which are stagged on each other. I need to create a label (or text-window / description, doesn't matter) which should contain values from different layers. Creating a regular label I can only choose attributes from this layer. Because the features have different nodes, it is not possible to just merge the layers.
You can create a virtual layer that will compute the intersection between the layers and retrieve the desired values to be labeled. Then you would put a label on this virtual layer.
Here is an example between two line layers, but this approach can be generalized to other types.
Go to the menu
Layer / Add layer / Add - Edit virtual layer and put the following definition:
SELECT a.myField nameA, b.myField nameB, st_intersection(a.geometry, b.geometry) FROM myLayer1 a, myLayer2 b WHERE st_intersects(a.geometry, b.geometry)
This will create a new layer. Label it using the formula
nameA || nameB or any other one that would concatenate the information to be shown.
Have a look at the refFunctions Plugin. It allows you to create a reference to another layer and you can specify the field you want to reference:
- Point layer named points with id and field1 fields
- Polygon layer named poly with id field
to Create the label for the poly layer I used this:
concat("id", ' with other ID: ', geomcontains('points', 'id') ,' and name :' , geomcontains('points', 'field1'))
- "id" is the ID field of poly
- geomcontains is the function from refFunctions
- 'points' references my points layer and
- 'id' is the ID field of points