I've got the same task with polygons' and points' layers (most of points are snapped to polygons, so I have to be precise).
I assume, the best way to solve this task is by transfering all layers to the polygon type:
- Create a special field in both (or more) layers which would help you to recognize which layer each feature is from. Make sure your 'polygon' layer has all the fields which are in others (in my case 'points') layers. It prevents you to lose data.
- Create buffer around your 'points' layer.
- Copy created objects to the 'polygons' layer. You have to make sure you can recognize "external" features. In my case, they have the code '1'.
- Move all the items.
- Select features from your 'polygons' layer, which has the appropriate layer code (in my case '1').
- Create centroids from selected features.
- Replace your points from 'points' layer with new created ones. Points remain snapped.
Still not perfect, but way better :)
It's also possible to do the same with the lines' layer
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
after moving the pole polygon:
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.
Best Answer
This could potentially be down to the two different layer panels:
One is Layer order and the other is Layers:
Untick the "Control rendering order" in the Layer order panel, which will then allow you to control it through the main Layers panel.
To turn these on and off use the: View>Panels menu