12

I am creating a map with airports, using an airplane symbology (svg). Instead of having all small plane symbols turned north, I would like to rotate them to be all turned to Paris. I have 28 airport points in one layer, and the point of Paris in another layer.

I assume I need to draw lines between each point to Paris, then calculate some rotation angle that I can then use in the symbology.

How is this best achieved?

14

I am making the following assumptions:

  1. You are using a projected coordinate system
  2. Your data is in two separate layers called cities and planes

This solution should also extend to the case of multiple cities

Onto the solution:

  1. Add a unique id field to planes called plane_id
  2. Add a unique id field to cities called city_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)
  3. Add a field to planes called city_id and set it equal to each plane's corresponding city's city_id value from cities (in OP's case, this will just be a single value)
  4. 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)
  5. Add a real/float/double field to spokes called angle and set it equal to angle_at_vertex(geometry:=$geometry,vertex:=0) (Source)
  6. Join spokes to planes using the field plane_id for both layers
  7. (Optional) Save planes as a new layer if you want to preserve the join
  8. Set the rotation angle of the planes symbol to the angle field which was just joined into plane (see pic)

enter image description here

Result:

enter image description here

9

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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