I have 3 points in one layer as shown in the first image. I am trying to connect a building points with junction point by 2 lines. For demo, I have manually drawn a lines in image 2. Here, I am trying to achieve two things:

  • Connect points (buildings) with Junction by lines.
  • Save the data of start point and end point of connecting lines in seperate table (layer) as shown in image 2 (rightside).

Overall, there will be 3 features in points table and 2 features in line table.

What I have tried and search?

  1. I have tried points to path using Menu Processing / Toolbox / points to path. It only connect one building with junction point with no attributes (startpoint,endpoint) saved in the table.
  2. I have also searched for the exisiting answers 1, 2, 3, 4 but I couldn,t able to solve the problem.

![enter image description here

![[2]: https://i.stack.imgur.com/AAp3O.png

  • I don't understand the question, but maybe a virtual layer can help: SELECT make_line(a.geometry, b.geometry) geometry, a.id objectid, a.mrid as 'start_point', b.mrid as 'end_point', a.Class FROM newpoints_2021 a, newpoints_2021 b WHERE b.id='36' AND a.class IN ('building') Jan 13, 2021 at 15:36
  • Hi @CyrilMikhalchenko. The question is to connect the points with lines and then save the start and end data of connecting line in seperate layers as shown in image 2 (rightside).
    – Case Msee
    Jan 14, 2021 at 0:25
  • @CyrilMikhalchenko. The important part is to save the data of start and end points in the new layer.
    – Case Msee
    Jan 14, 2021 at 0:42
  • Did you try to run the query I suggested with the virtual layer and then save the result? Does it meet your expectations? Jan 14, 2021 at 8:28

1 Answer 1


You can use Menu Processing / Toolbox / Geometry by expression to create the lines you want:

if ( 
    "Class" = 'building' ,
    make_line (
        geometry (
            get_feature (

enter image description here

If you want to have start- and end points as actual geometries/separate layers, you can just use Menu vector / Geometry tools / Extract vertices and set the lines created before as input.

To visualize start- and endpoint of this line (without creating actual geometries/new layer), add a new symbol layer / Geometry generator / geometry type: point and add the following expression (see screenshot below).

collect_geometries (
    end_point ( $geometry ), 
    start_point ( $geometry )

enter image description here

  • Hi @babel. I can,t able to create line. Can you please share which sample files are you using? My shape file is available here dropbox.com/sh/nwpbnb61riezr5v/AAC3vGwkn-YZDna0DwnbXNJOa?dl=0
    – Case Msee
    Jan 13, 2021 at 11:48
  • 2
    You must adapt the names of the layer and the fields to your use case: you have Junction with uppercase, the name of your layer is 'newpoints_2021' instead of 'points' etc. With the data/names you provided, I was able to create the line using: if ( "Class" = 'building' , make_line ( $geometry, geometry ( get_feature ( 'newpoints_2021', 'Class', 'Junction' ) ) ), NULL )
    – Babel
    Jan 13, 2021 at 13:27
  • If you use geometry generator on a symbol layer, instead of the layer name you can use the variable @layer. However, when using Geometry by expression, unfortunately this does not work.
    – Babel
    Jan 13, 2021 at 13:30
  • Thank you. I able to get the connecting lines but the output layer (Modified geometry) is similar to input points as shown here ibb.co/dmS87pC . It does not save the start and end points as shown in the image 2 of question.
    – Case Msee
    Jan 14, 2021 at 0:41
  • For intance, building 1 is connected with junction by line. The output layer should save the connected points by mrids. lets say the line is connected FROM building mrid (d2127ed8-de59-427a-a22f-ac7765637b9f) TO Junction mrid (4c67ad24-7bcb-4161-a410-23196419aab4). The information of FROM and TO should be saved in the output file with mrid. This is what I have also tried to show manually in image 2 (rightside) in question.
    – Case Msee
    Jan 14, 2021 at 1:26

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.