QGIS - Rotating all symbols to face a single point
I am making the following assumptions:
- You are using a projected coordinate system
- Your data is in two separate layers called
cities
andplanes
This solution should also extend to the case of multiple cities
Onto the solution:
- Add a unique id field to
planes
calledplane_id
- Add a unique id field to
cities
calledcity_id
(it will just be one value in OP's case, but if you have multiple cities then this solution will extend to that case as well) - Add a field to
planes
calledcity_id
and set it equal to each plane's corresponding city'scity_id
value fromcities
(in OP's case, this will just be a single value) - In the Toolbox, run Join by lines (hub lines), naming the output
spokes
with the following inputs:- Hub layer:
cities
- Hub id field:
city_id
- Spoke layer:
planes
- Spoke id field:
city_id
(This is actually where you determine to which hub each spoke will be connected to, not the unique id field of each spoke)
- Hub layer:
- Add a real/float/double field to
spokes
calledangle
and set it equal toangle_at_vertex(geometry:=$geometry,vertex:=0)
(Source) - Join
spokes
toplanes
using the fieldplane_id
for both layers - (Optional) Save
planes
as a new layer if you want to preserve the join - Set the rotation angle of the
planes
symbol to the angle field which was just joined into plane (see pic)
Result:
A one-step scenario :
you add a virtual field in your airports table using the following expression :
angle_at_vertex( make_line( centroid($geometry), centroid( geometry( get_feature( 'destinations', 'name', 'PARIS')))), 0)
And you use that angle value ("angle") as data-defined rotation as mentionned by @wfgeo
I assume your "PARIS" point layer is called 'destinations' and has a 'name' attribute.