2

I have a question if there is an expression to indicate the name of the layer on which the shape lies. Exactly what I mean: I have a map created based on Open Street Map regarding public facilities like hospitals and schools. The polygons representing them (there are quite a few...) are located in different municipalities (33 to be exact). Is there any way to indicate in the attribute table of a shape representing e.g. schools, that e.g. this school lies in municipality Y, and that school in municipality Y? In other words, is it possible to link data in such a way between two shapefiles? I don't know if I expressed myself correctly...

example of what I try to achieve...

1 Answer 1

4

Since QGIS 3.16 either:

array_first(overlay_intersects('layername of districts',"Field containing commune number"))

or

array_first(overlay_within('layername of districts',"Field containing commune number"))

In versions older than 3.16:

array_first(aggregate('layername of districts','array_agg',"Field containing commune number",filter:=intersects($geometry,geometry(@parent)))

respectively replace intersects() with within()

2
  • Thank you thank you thank you. I love this forum so much !
    – crtnnn
    Commented Apr 4, 2022 at 16:14
  • 2
    As a new user, please be adviced that this side tries to avoid "thank you" messages. Instead, it encourages you to accept the answer and/or upvote it: click the checkmark right to the answer to accept it - see: gis.stackexchange.com/help/someone-answers Just click the checkmark, see here: meta.stackexchange.com/questions/5234/…
    – Babel
    Commented Apr 4, 2022 at 17:04

Your Answer

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

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