QGIS – Moving Two Layers with Different Geometry and Snapped Vertices

geolocationgeometrylayersqgisvertices

I would like to be able to move two layers that look like you see below:

enter image description here

Basically, when I move the polygon object, to which the lines are snapped as a separate layer I want them to be intact at the end. I can't merge these layers and promote them to multipart because I need them separately. I just want to know the option, which will allow me to make the drag including these 2 layers (or more optionally).

Similar issues were potentially here:

but they didn't solve my problem.

Is it possible to do operation such as this in QGIS?

Best Answer

One option is to use an endpoint point layer, the existing pole polygon layer and to compute a virtual lines layer, that is updated each time the map is moved.

The endpoint must have a poleID attribute, that is populated of the polygon it should be connected to.

The pole layer must have a unique poleID attribute.

The virtual layer can have any attribute from the endpoint or the pole layer, in addition to create a line between the two geometries.

When you touch the map (pan, move, refresh etc), the lines are automatically recomputed. You can use the virtual layer like any other layer, or you can export it to another format if you need to persist the data.

Go the the menu layer / add layer / add-edit virtual layer and enter the following query.

select p.poleID, pt.ptID, ST_ShortestLine(p.geometry,pt.geometry)
from endPoints pt
join pole p
 on pt.poleID=p.poleID

enter image description here

after moving the pole polygon:

enter image description here

PS: this solution produces real lines that can be used for further analysis, in contrast with the excellent geometry_generator solution that produces lines for display only.

Related Question