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

Taras
  • 32,823
  • 4
  • 66
  • 137
Kan375
  • 21
  • 1

2 Answers2

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

Matt
  • 16,843
  • 3
  • 21
  • 52
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

Taras
  • 32,823
  • 4
  • 66
  • 137
JGH
  • 41,794
  • 3
  • 43
  • 89