4

I am using the geometry generator to learn how to generate vectors using expressions. Currently, I have a point vector, and I would like to create horizontal lines (shown in red: manually drawn) connecting the points, as illustrated in the image below:

Requires Lines

I am aware that the make_line function allows us to create lines. How should I modify my code to generate a line that passes through these points horizontally?

The condition I intend to use is to connect lines with the same Y coordinates.

make_line(collect($geometry, group_by:=y($geometry))
Taras
35.7k5 gold badges77 silver badges151 bronze badges
asked Nov 29, 2023 at 14:33

1 Answer 1

7

Easiest is probably

make_line (array_agg ($geometry, group_by:=$y))

Or, extending your version, you can add a geometries_to_array() function: it is available since QGIS 3.28, so for older versions use the expression above:

make_line( 
 geometries_to_array (
 collect ($geometry, group_by:=$y)
 )
)

enter image description here

answered Nov 29, 2023 at 14:54
3
  • Is there any way to extract this generated line in any vector format? or is this only useful for visualization purpose? Commented Nov 29, 2023 at 15:02
  • I tried using 'Geometry by expression' but there is error 'Evaluation error: Cannot use aggregate function in this context.' Commented Nov 29, 2023 at 15:07
  • Yes, Geoemtry by expression would be the way to do so. Unfortunately, as you realized, it does not work with aggregate functions. Maybe post this as a separate question. Commented Nov 29, 2023 at 15:12

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.