QGIS Distance Matrix – Generate Line Geometry Output

distance matrixlineqgisqgis-plugins

I have a series of Output Area centroids and I want to create a matrix of lines between each point (every point connected to every point), which is effectively what the distance matrix tool does (I think). But I also need the line geometry for visualisation purposes. Can anyone tell me how to do this?

Best Answer

As you have Distance matrix output, use its InputID and TargetID fields to build connecting lines.

enter image description here

Just open the Layer properties | Symbology and select Geometry generator.

enter image description here

If your original point layer name is points and it has id field (the one you used to create the Distance matrix), the expression would be:

make_line(geometry(get_feature('points', 'id', "InputID")), 
          geometry(get_feature('points', 'id', "TargetID")))

It will give you these connecting lines:

enter image description here

Related Question