2

I am looking to connect points with a line using Geometry Generator or Virtual layer. Each point has a unique number, a code and a line number. The goal is to display in QField application the lines according to the points recorded on the field. Someone can help me?

Here is an example:

enter image description here

1

2 Answers 2

4

You could use this expression on a Geometry Generator symbol layer of type LineString:

with_variable('group', "code"||'_'||"line number",

case
when
    $id = array_min(
              array_agg(
                  $id,
                  group_by:=@group
              )
          )
then  
    make_line(
        array_agg(
            expression:=$geometry,
            group_by:=@group,
            order_by:=$id
        )
    )
end
)

Groups are created by concatenating the "code", an underscore, and "line number" fields. This value is assigned to a variable for better maintainability.

The case statement is to ensure the line is rendered only once per group, rather than once for every point. See this thread for more details.

enter image description here

3

You can achieve it using a Virtual layer.

Go the the menu layer / add layer / add-edit virtual layer and enter the following query. You may want to add more fields and a unique ID.

select MakeLine(pt.geometry) as geometry
from myPointLayer pt
group by pt.code, pt."Line num"

If the input points are not already ordered by ID, you may have to include a sub-query to sort the points first, then apply makeLine on it.

enter image description here

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.