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?

Mark
  • 965
  • 6
  • 12

1 Answers1

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

Mayo
  • 3,902
  • 3
  • 22
  • 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 Aug 29 '22 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 Aug 30 '22 at 08: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 Aug 30 '22 at 13:42