TransWikia.com

Inserting attribute value in Print Composer into label based on spatial relationship

Geographic Information Systems Asked on September 6, 2021

I have this print layout in QGIS print composer/atlas in which I only have one layer being shown: land parcels. I am interested in having a label that will show what is the attribute of another layer I have based on a spatial relationship like intersects.

This other layer is a layer of land uses. The idea is to have next to the map what are the allowed uses for that particular plot. The image below recreates what I need.

enter image description here

It seems there is no straight way to build this expression within the context of the QGIS Print Composer, but I think I am missing something. The closest I got an expression that feeds my label object is this expression:

if(intersects(@atlas_geometry, geometry(get_feature('land_use', "fid", "fid" > 0))),
  "use",
  'No restriction')

However this expression is always returning No restriction and this I am absolutely sure it cannot be. Therefore, this leads me to believe the intersects part is not being evaluated as I think it is. What could be wrong here?

One Answer

This can be achieved using an agregate function. In this case the expression is:

aggregate(
 layer:= 'land_use',
 aggregate:='concatenate',
 expression:= land_use,
 concatenator:=' ',
 filter:=intersects($geometry, @atlas_geometry)
 )

Two notes on this. (1) Most of the credit goes to Ujaval Gandhi thanks to this blog entry. (2) I find it a bit counter-intuive that a non aggregation problem is solved using an aggregate. Still curious to know if alternative solutions exist.

Correct answer by Lisdengard on September 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP