7

I would like to know if there is any way to generate a connecting line between 2 points layers (blocks-points representing a watershed, concpoints-points representing the concentration location of the flow from that watershed) through the geometry generator in the style panel of QGIS, with the specification that in some cases there is a relationship of several basins concentrated in a single point.

In these specific cases, the attribute "ID_UC" that indicates which basins contribute to a concentration point is a string that separates the basin ID's ("ID_QE" attribute of the layer blocks) using a comma, as in the following image:

enter image description here

As you can see in the following image, I was able to accomplish the task for simple cases where there is a ratio of 1 basin to 1 concentration point, using the expression

make_line(
   start_point($geometry),
   geometry(
       get_feature(
           'concpoints',
           'ID_UC',
           "ID_QE" 
       )
   )
)

enter image description here

I imagine that there is a way within the geometry generator to transform the string field "ID_UC" into an array, where each element would be the ID of a different basin, and thus be able to make this connection between the blocks layer and the concpoints layer, or another way to generate these connection lines.

Download example project and layers

1 Answer 1

8

You can do this using array_foreach() function

collect_geometries(array_foreach(string_to_array( "ID_UC" ),

Use this expression on the 'concpoints' layer.

collect_geometries(array_foreach(string_to_array( "ID_UC" ),
make_line(
    start_point($geometry),
    geometry(
        get_feature(
                   'blocks',
            'ID_QE',
            @element
        )
    )
)))

enter image description here

1
  • That was exactly the result I was hoping for, I was approaching the problem using the geometry generator from the blocks layer, but the important thing was the end result. Thank you very much. Commented May 18, 2022 at 18:48

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.