QGIS Geometry – Creating All Possible Line Segments Between All Points in QGIS

geometry-conversionpointpoints-to-linepolyline-creationqgis

I want to connect all points in a point feature with every possible line segment using QGIS.

For example, how a pentagon has five points with ten line segments connecting them all to form a pentagram inside.

Alternatively phrased: How do I make spokes when all the points are hubs?

I don't care about the order, I just want every connection between two points as one line each. Is there a tool or script that can do this in QGIS?

This topic (How to generate line segments between all points) is the closest to what I want but the plugins are no longer supported.

Best Answer

You can achieve your goal using the Field Calculator.

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

 collect_geometries( 
   array_foreach(
     aggregate('point_layer','array_agg',$geometry),
       make_line($geometry,@element)
   )
 )

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

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

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

enter image description here