2

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:

enter image description here

Any suggestions?

asked Aug 12, 2022 at 14:56
1
  • Please check this question for a direction. It's no duplicate, but a rather similar one. Commented Aug 12, 2022 at 15:02

1 Answer 1

4

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

answered Aug 12, 2022 at 16:05
3
  • Is it possible that i get only the start point and the end point concatenated "c,e" (in the case of 3 points connected)? Commented 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? Commented 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? Commented Aug 30, 2022 at 13:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.