I'd like to know how to concatenate points values (attribute data), using fields calculator of QGIS, putting this concatenation in a new field of the linear feature which connect some points of these.
For example, i'd like to get a new field called "name" in the linear layer, putting the concatenation of the field "type" of the points connected; from start point to the end point:
Any suggestions?
-
Please check this question for a direction. It's no duplicate, but a rather similar one.Erik– Erik2022年08月12日 15:02:59 +00:00Commented Aug 12, 2022 at 15:02
1 Answer 1
Try something like this in the field calculator in the lines layer
array_to_string(
overlay_intersects(
'layer',
"type"
),
','
)
Replace layer
with the layer name / id of the point layer.
Use this to return the data ordered by the position of the point in the line:
aggregate(
layer:='Points layer name/id', -- set here the points layer name/id
aggregate:='concatenate',
expression:=to_string("type"), -- set here the field to be concatenated from points
filter:=intersects(
$geometry,
geometry(@parent)
),
order_by:=array_filter(
array_foreach(
generate_series(
1,
num_points(geometry(@parent))
),
array(
@element,
point_n(
geometry(@parent),
@element
)
)
),
intersects(
$geometry,
@element[1]
)
)[0][0],
concatenator:=',' -- set here the concatenator
)
Result, red tags are the concatenated fields from points. result
-
Is it possible that i get only the start point and the end point concatenated "c,e" (in the case of 3 points connected)?Mark– Mark2022年08月29日 15:01:40 +00:00Commented Aug 29, 2022 at 15:01
-
Sorry, I didn't make myself clear. I'd like to have an output as the question on top (all 3 vertices concatenated from start point to the end), but i'm trying your solution (array_to_string.....) and it doesn't work. Is it possible?Mark– Mark2022年08月30日 08:11:57 +00:00Commented Aug 30, 2022 at 8:11
-
It works! Thx! Is it also considered the order of the points in the concatenation (as in the image) or the "type" will be random?Mark– Mark2022年08月30日 13:42:29 +00:00Commented Aug 30, 2022 at 13:42