I have two layers as the whole project in EPSG:4326:
- polygon layer of countries
- linestring layer of routes
I want to concatenate the country names (those are stored in "name" attribute) based on intersection with linestring vertices ordered by linestring vertices order.
In my example (vertices numbered with vertex number) I'm expecting the result something like this:
- for red route: Czech Republic, Slovakia, Hungary, Austria
- for blue route: Slovakia, Poland, Czech Republic (no matter if result will be arrayed of strings or string, I can handle it later)
I made the various expressions that allow me to get the country names for a particular vertex number, but the concatenation is a problem. I made an expression that iterates over the vertices and for each vertex it should concatenate the intersection country name, here is the code:
array_foreach(
geometries_to_array(nodes_to_points($geometry)),
with_variable(
'n_point',
@element,
aggregate(layer:='countries',
aggregate:='concatenate',
expression:="name",
filter:=intersects($geometry, n_point)
)
)
)
I'm on Win 11 Pro, version 23H2; QGIS 3.28.13
I found Error with array_foreach when using together with aggregate in QGIS expression that deals with similar problem as it seems to be the problem/bug of aggregate + array_foreach usage
Can provide the project with dataset if necessary.




@n_point, however I did not find a way to have it work (I end-up with as many points that the line has but with the name of le last country repeated as many times)