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:
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))
1 Answer 1
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)
)
)
-
Is there any way to extract this generated line in any vector format? or is this only useful for visualization purpose?unknown123– unknown1232023年11月29日 15:02:04 +00:00Commented 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.'unknown123– unknown1232023年11月29日 15:07:31 +00:00Commented 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.Babel– Babel2023年11月29日 15:12:02 +00:00Commented Nov 29, 2023 at 15:12
Explore related questions
See similar questions with these tags.