I have 6 points in one layer as shown in the first image. I am trying to:

  1. connect points with lines in a required sequence.
  2. Save data of line connections (From_point and To_point) in the seperate layer.

For demo, I have manually connected the lines (green) and shown the sequence (red) with numbers in Image 1. The sequence of connecting lines should be as follows:

Sequence From_point To_point
1 (building1) to (Junction) 7b9f aab4
2 (building2) to (Junction) d052 aab4
3 (Junction) to (Breaker) aab4 edb3
4 (Breaker) to (Station) edb3 c037
5 (Sation)) to (MainSource) c037 4d3c

Initial attempt with points to path:

I tried to achieve this Menu Processing / Toolbox / points to path and Points2One plugin but it does not maintain the required sequence of connections as shown in Image 2

![![![![enter image description here

![enter image description here

  • 1
    You're trying to create a multi-line, since there's a branch in it. A multi-line is no path, hence the tool wont "work". You could create all the single line segments and then dissolve them, if you only care about the geometry.
    – Erik
    Jan 14, 2021 at 8:52
  • 1
    Is there any rule on how to connect points? The table doesn't give a clue. I understand (from table) that the buildings are connected to junctions. That's fine. But, what if there are many junctions around the buildings? Jan 14, 2021 at 9:24
  • @Erik. How about this case i.stack.imgur.com/25HKy.png ? I make it simple by removing one building class. The connection sequence is building- Juntion- breaker-Station-Main source. Is it possible that make line function in geometry generater will connect the line and save the start and ending point of every line in new layer as I tried to manually show here i.stack.imgur.com/25HKy.png ?
    – Case Msee
    Jan 14, 2021 at 13:03
  • @KadirŞahbaz. If we ignore the sequence, Is it possible to connect points with lines and save the start data and End data of every line in new layer? For instance, building is connected to junction:attribute 1 in new layer, then junction to breaker: attribute 2 in new layer and so on as I have tried to show here i.stack.imgur.com/25HKy.png
    – Case Msee
    Jan 14, 2021 at 13:09
  • @KadirŞahbaz. The rule is to connect the points according to Id in points layer (ascending order). I mean ID:1 should be connected to ID:2 then ID:2 with ID:3 and so on..
    – Case Msee
    Jan 14, 2021 at 13:11

2 Answers 2


Solution with algorithms and expressions

For the fist part of your problem :

You could use the geometry by expression algorithm and use this expression :

            'LAYERNAME' ,
            filter:="id" =  attribute(@parent, 'id')+1),
        make_line($geometry, geometry(get_feature('LAYERNAME', 'mrid',@element)))

It's not the best approach to what mentioned Kadir. If there are 2 ore more children this expression will build a multilinestring.

For the second part, apply the multiparttosinglepart algorithm on the output of the first treatment. The mrid field correponds to the start and you can obtain the end by adding a new fied on the ouput with this formula :

'concatenate', "mrid", filter:= intersects($geometry,end_point(geometry(@parent)))) 

*intersects is used in place of equals

** LAYERNAME is the SOURCE LAYER (point layer)

  • Very useful answer for first problem. Regarding second part, I am trying to get the Start and End data of every line and save the attributes in new layer (Ignore the sequence in this case). Is that Possible with geomerty generator or any other method? Like this one i.stack.imgur.com/iXGln.png
    – Case Msee
    Jan 14, 2021 at 12:32
  • 1
    Just add the second part
    – lejedi76
    Jan 14, 2021 at 13:23
  • Can we use Virtual layer instead of iterating multiple algorithms? The purpose is to: connect lines and get the START POINT and END POINT of each line? Might be using JOIN, ST_INTERSECTS(ST_STARTPOINT(c.geometry),n.geometry), ST_INTERSECTS(ST_ENNDPOINT(c.geometry),n.geometry)
    – Case Msee
    Jan 14, 2021 at 13:51
  • I was also thinking about PyQGIS where the code will connect the points with lines and save the STARTPOINT and ENNDPOINT of lines in new layer.
    – Case Msee
    Jan 14, 2021 at 14:01
  • Any idea, how we can deal with this kind of situation i.stack.imgur.com/dgofg.png . For instance, if I have only one point layer with 6 points. How can I connect a single node (cubicle146354) with 5 other nodes ( service points) along with a substattion site as shown in the above Image. What I am trying to achieve here is : connect nodes (point) with lines and save the Startpoint (FromNode) to Endpoint (ToNode) data of every line in new layer. The virtual layer should connect the lines and save the table similar to rightside of image.
    – Case Msee
    Jan 21, 2021 at 12:21

All in one solution with virtual layer

For your probleme you can indeed use virtual layer, I didn't know you want use this method :

build_segment as (
  a.mrid as start_point, 
  b.mrid as end_point,
  makeline(a.geometry, b.geometry) as geometry
from <layername> a
left join <layername> b on (a.id + 1 = b.id  ))

from build_segment
where geometry is not null

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.