QGIS – Generating Line Segments Between All Points Using QGIS

geometry-conversionpointpoints-to-linepolyline-creationqgis

How do I create a vector layer with a network of line segments drawn between every point in another vector layer?

Basically, I am trying to create something similar to a hub/spoke network, except that instead of having a single hub and the other points are destinations, I would like every point to be treated as a hub with a direct connection to every other point.

I have managed to get the hub lines from one point to every other using the MMQGIS plugin "Hub Lines" module, but it seems that I would need to re-run it for each individual point.

Is there a way to just do it all in one go in QGIS?

It may be worth noting that I don't need to know the distances between the points; I'm looking for the azimuths.

Best Answer

I think that it might be easiest to do with ST_ShortestLine with PostGIS http://postgis.net/docs/ST_ShortestLine.html or with a similar ShortestLine function in Spatialite https://www.gaia-gis.it/gaia-sins/xmlBlob/spatialite-sql-latest.html.

You said you have only points but those functions can be used for other geometries as well.

Here is an example with Spatialite.

SELECT
    shortestline(a.geometry,b.geometry) AS geometry, 
    a.rowid AS start,
    b.rowid AS end 
FROM
    source_table a,
    source_table b 
WHERE
    a.rowid < b.rowid;

enter image description here