Friday, 29 September 2017

How to rotate (svg) symbols in QGIS map composer to match map rotation?


Because of my thesis layout requirements, I have to rotate 270° some of my maps in composer.
There are (many) svg smbols (icons), and they are rotated as well.
I would like to (non-)rotate them in order to keep them upright, so one doesn't have to continuosly rotate the page or the neck ;)
Is there a way to do that? Note that I would like to do it on the composer stage since some of my maps are normally placed north-south. Thanks for the attention!



Answer



Here's an approach which would work in QGIS 2.2 and above. You can set a data defined rotation on the symbol which matches whether the map is being rendered in a specific composer map or to the main map canvas - this is done using the '$map' variable. $map will be 'canvas' for the main window, or a map item's id if it's being rendered in a composition.


So, to begin, set the map item's id to something like "rotated_map_01": enter image description here


Then, in your layer's symbol properties, click the "Data Defined Properties" button: enter image description here


Check "Angle" and click the expression builder button. You want to enter an expression along this lines of



CASE WHEN $map LIKE 'rotated_map%' THEN 270 ELSE 0 END

enter image description here


This expression will return 270 if the map item's id begins with "rotated_map_", or 0 otherwise. So, in any composer maps with an id "rotated_map_01", "rotated_map_02", etc the symbol will be rotated 270 degrees!


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...