QGIS Vector – How to Create Lines Between Points from Different Layers in QGIS

qgisvector

I would like to connect my points with one point at the different layer, like you see below:

enter image description here

enter image description here

but the simple option like Points to path doesn't work here, because it applies to one layer.

I found some options here:

Draw lines between points

and here:

Creating lines between Points in QGIS 3.6.2

where I tried to use the Geometry by expression. Unfortunately, I wasn't successful.

I also tried the Point Connector plugin:

https://www.youtube.com/watch?v=aZTpZ_NzwN8&ab_channel=NextGIS

but it doesn't work as expected.
enter image description here

I need to link all the selected points with one green point, which is already under a different layer, and repeat this step for other green points, where other points will be allocated (like you can see in the data attribute table above).

Is there any way to make the lines between points, where some points must be allocated to the other point belonging to the different layer?

UPDATE:

I tried to use the Join by lines option as pointed out in the comment below:

Joining many points with lines?

by creating the same column in the data attribute table

How to copy same values to another field in attribute table in QGIS using field calculator?

which now looks like this:

enter image description here

but it didn't work, I have the "Hub lines" created, but my new data attribute table is empty.

enter image description here

What am I doing wrong here?

Best Answer

OK, the basic solution is here:

Joining many points with lines?

but the primary reason, why I got nothing in the attribute date earlier was the wrong combination between the unique columns in both data attribute tables. Since the link above states, that it's enough when we use just unique columns (with unique data) between both data attribute tables I would say, that it's not always true. It depends on what our string is and does the column content matches itself between these 2 unique columns considered. If, for instance, we will have some discrepancies there, then the tool probably will throw just empty records. Thus much better is to use just ID as the unique column in both layers, it's the safest approach, which guarantees the result as below:

enter image description here

enter image description here