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?

  • 1
    An option could be to have a point layer with the external line ends, an attribute "poleID" on these points, and a virtual layer that joins the points to the "poles" and creates the lines on the fly.
    – JGH
    Commented Dec 6, 2021 at 16:29
  • I don't know how to do that. Could you clarify it with some steps?
    – Geographos
    Commented Dec 6, 2021 at 16:30
  • Ok, Thanks. Now it starts to make sense, although I can't drag these lines the same as the polygon. They remain fixed in that given location. Here is the link to my screenshot: imgur.com/gallery/vpGi5WF
    – Geographos
    Commented Dec 7, 2021 at 14:19

2 Answers 2


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.

  • OK, I've managed with it. Unfortunately, when I move the polygon, the lines remain in the same place. I have to redo the query if I want them to be dragged where the new place of the polygon is. Is something I could do here in order to make these lines draggable in the real-time?
    – Geographos
    Commented Dec 6, 2021 at 17:46
  • @MKR pan the map after having moved the polygon (or refresh, or zoom)
    – JGH
    Commented Dec 6, 2021 at 17:47
  • Ok, now I see. Thanks. Let me play with it.
    – Geographos
    Commented Dec 6, 2021 at 17:51

You can use Geometry by expression to create the new lines, based on the old ones. Use this expression and adapt it to your use case - here, the line goes to the centroid of the shifted polygon:

make_line (
    start_point ($geometry), 
    centroid (
        geometry (

This is how the dialog window looks like:

enter image description here

Here visualized with geometry generator and the same expression to show how it works: enter image description here

Here in detail with the centroids made visible: blue = orgininal, red = shifted polygon/centroid; black lines = initial lines, red dotted = created line. White dots are start_point of the lines (if they are end_points, simply change start_point to end_point on line 2 in the expression: enter image description here

  • I have the new layer "Modified geometry" created, but I can't see it on my map. Is this expression valid then?
    – Geographos
    Commented Dec 6, 2021 at 17:21
  • Without sharing your data or at least posting a screenshot, it's difficult to say what happened. Did you adapt the name of the layer (shifted_polygon in my case)? Is the polygon you shift really feature no. 1? Are start-points of the line really those outside the polygon? How did you make settings in the Geometry by expression dialog: did you set output geomtetry type to line? And did you use the line layer as input?
    – Babel
    Commented Dec 6, 2021 at 17:30
  • Yes I did, but I don't know what to put in the dialog window.
    – Geographos
    Commented Dec 7, 2021 at 13:55
  • Added the dialog window to my answer
    – Babel
    Commented Dec 7, 2021 at 14:12
  • OK, now it makes sense. However, my lines remain fixed in the position. Is there something I have to do here? They do not move at all. The screenshot is here: imgur.com/PwDEz6A
    – Geographos
    Commented Dec 7, 2021 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.