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...
1 Answer
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()
-
-
2As 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/…– BabelCommented Apr 4, 2022 at 17:04