I have 10 points in QGIS layer as shown in Image 1.

  • I am trying to connect points with lines in required sequence as shown in Image 2. However, when I tried to connect all points with virtual layer, the connections are not according to my required sequence (yellow lines) as shown in Image 3. What should I do to get the required connections?

  • The features in attribute table are shown here. Do I need to change the IDs of points to achieve the required connections?

  • I was thinking about parent layer and child layer for required connections but I am not sure how to achieve that.

  • The shapfile is available here

Virtual layer query that I have tried (Image 3):

In this query, I am trying to connect points with line by saving the start and end points of each connecting line.

build_segment as (
  a.GlobalID as start_point, 
  b.GlobalID as end_point,
  makeline(a.geometry, b.geometry) as geometry
from Points_Colac_Demo_advanced a
left join Points_Colac_Demo_advanced b on (a.OBJECTID + 1 = b.OBJECTID))

from build_segment
where geometry is not null

![enter image description here

enter image description here

enter image description here

  • 1
    what's the diference with your previous question ? As said last time you don't give any clue indicating how points should be connected ... id's are not enough ... class information is certainly to be taken in account ... you're not building a simple line with a given points order you're building a network with (probably) building rules ...
    – Snaileater
    Feb 21, 2021 at 13:45
  • I have added more clues in the attribute table by following your advise i.sstatic.net/LHyKf.png. Are these clues are enough to get the required result? If the clues are enough what are the best options/ techniques to get the required output.The question was also what clues should I add in the table to get the required connections (network).
    – Case Msee
    Feb 22, 2021 at 3:26
  • In order to create a line based on your initial data and drawing you must create 9 segments and use 18 initial points... Feb 22, 2021 at 12:59
  • 1) create a separate table with the from/to ID. Doing so will allow a single point to be connected to multiple ones. 2) don't rely on OBJECT_ID, never. They are not stable. Instead, create a new field that you control (the initial values can be a copy of object_id) 3)your query is almost the proper one. Do a 3 table join and link on a.id = relationTable.FromID and b.id = relationTable.ToId
    – JGH
    Feb 22, 2021 at 13:23

2 Answers 2


Looking at your files, your feature id and OBJECTID are different, I would first update the OBJECTID column with the feature id (using the calculator $id varible) then create a new column called 'to_id' (or something else you want. then attaribute this new column with the connecting points id (from the updated UNIQUEID column).

You can then simply apply a geometry generator to generate the lines on the fly, see below screenshots:

New Browser

Map View

EDIT: You can also use the "Join by lines" option in the processing toolbox to generate the lines. Process would still be the same as my original answer, after updating the IDs you duplicate the layer and use the tool on the two layers joining the original OBJECTID with the to_id field. See image:

Join Lines

EDIT 2: To use the value of a feature from the browser you would use the get feature options:

    $geometry ,  
        get_feature( 'Points_Colac_Demo_advanced',  'OBJECTID' , to_id  )

Simply substitute for the filed you want to use "GlobalID" in your case.


Just dropping this here for a Virtual Layer: Connect all points with all other points with lines and putting length in meters into the attribute table.

  a.fid * b.fid AS id,
  make_line(a.geometry, b.geometry) AS line,
  st_length(make_line(a.geometry, b.geometry)) AS length
FROM locations a
JOIN locations b ON b.fid > a.fid

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.