You can connect the points using geometry generator. Let's say you have two points layers, where the fid is matching the potints in each layer you want to connect with a line. For demonstration, I just created two layers with 10 random points on each.
In one of the layers, add a symbol layer and use geometry generator for symbol layer type - see screenshot below. As geometry type, set LineString. Now you have to define the expression that generates your line (see below for how the expression should look).
The advantage is that the line adapts automatically to every change (adding or removing points, moving points to another place etc.) in realtime. And you don't need a separate layer. However, if you would like to make the lines permanent and store them in a separate file and show them in an own layer, you can paste the same expression to the geometry by expression algorithm (from processing toolbox).
The expression could look like this, just adapt to include the layer-name you use (instead of 'your_layer2' - layer names shold look someting like 'layer_2_d5d61a64_fe2d_44bf_a62e_1168bd89d4ea' - best select the layer from the expression editor):
make_line(
$geometry,
geometry(
get_feature_by_id(
'your_layer2', "fid" )
)
)
Explanation: Selecting layer 1, use make_line (point1, point2) to create the line. Point1 can be set to $geometry
, thus for each feature on your layer1, you want to have a line starting from there. The line should go to the corresponding point on the other layer: to the feature on layer2 with the same fid. Thus use get_feature_by_id(layer,feature_id)
and add the layer and the fid-field (if you just paste the field-name, it will take the field from layer1 - that is what you want, because the fid for layer2 should be the same as for layer1). Best use the column in the middle of the expression editor and select the entries from there (expand the headlines for map layers and fields and values). This returns you a feature. You have to use geometry(feature)
to convert the feature to a geometry (a point, in this case). The parameter (feature) is the expression we just discussed before.
You see the two points layers, each in a different color. I added a label with the fid to show how the lines are drawn.

processing
thentoolbox
then enterhub
in the search box)