# Draw lines between points

I am doing a research project for which I need to find an effective way for drawing lines between a number of points along a square. I need there to be a line between every point on the square in order to simulate the ability to cross the square whichever way a pedestrian pleases. Ideally the process should generate a new line layer.

The end result needs to look something like this: I have taken a look at previous posts on the subject, however the plugins that they recommend - PointsToPaths, Points2One - don't seem to be available in QGIS anymore, and the Points2One one doesn't work.

• First you have to determine the order in which the points should be connected. Feb 19 '20 at 7:33

One way to do this would be using a virtual layer.

1. Create X and Y fields in your point layer containing the x and y coordinates
2. Create a constant field with the same value
3. Save a copy of the point layer
4. Add a virtual layer joining by the constant value of both layers (original and copy) using the following expression:

SELECT *

FROM points

JOIN points_copy ON points.constant = points_copy.constant;

This will create a virtual layer that will contain every combination of X Y origin and destination coordinates. In my example I used 29 points thus resulting in a virtual layer of 841 points (29²). Just for symbolization purposes the point layer can be symbolized into lines using a geometry generator expression:

make_line( make_point( "cx" , "cy" ), make_point( "cx:1" , "cy:1" ))

To make a permanent layer I recommend using the tool XY to line from the plugin Shape Tools.

In QGIS you can make use of the virtual layers.

Go to `Layer/ Add layer/ add-edit virtual layer` and enter the following query. Feel free to add as many field as you want. The trick is to do a cross-join on the same table, generating every combination between the two layers.

``````select a.id, b.id, makeline(a.geometry, b.geometry) as geometry
from myLayer a, myLayer b
where a.id <> b.id
``````