Creating all possible line segments between all points using QGIS

You can achieve your goal using the Field Calculator.

Using the Geometry Generator, with Linestring geometry type, use this expression

collect_geometries( 
 array_foreach(
  array_agg($geometry)
 ,make_line($geometry,@element))
)

It will create an array of lines that connect any point with all the others point on the same layer.

You can create a new layer using the same expression in the Processing tool Vector Geometry > Geometry by expression

Here a screenshot that shows the result using the expression in the Geometry Generator

enter image description here


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

Let's assume there is a point layer "Layer" with its corresponding attribute table accordingly, see image below. Besides a new attribute might be created that will group points together, e.g. "id" on the icon below.

input

Step 1. Duplicate your initial point layer with 'RMC > Duplicate Layer...'.

Step 2. Make use of "Join by lines (hub lines)" (Spoke ID Field is "id"). Afterwards the application of "Fix geometries" and "Remove null geometries" is essential.

result

Step 3. If lines should be unique (only one connection between two points), then proceed additionally with "Delete duplicate geometries".

result_unique


To check whether the result is correct use the initial number of points, e.g. n.

  • when lines are doubled doubled
  • when lines are unique unique