[GIS] Automatic map rotation in map composer QGIS

atlasprint-composerqgis

The thing is that I wonder to make it possible to calculate automatically the map rotation in map composer. I have many maps in one file with their own projection parameters, and I would like to define map rotation in map composer based on projection formula (or smth else?)

e.g. location one specific map in project:

enter image description here

The projection is

enter image description here

In map composer map boundary looks like

enter image description here

And with selected rotation angle for the map with their projection parameters:

enter image description here

Map rotation angle is different for every map depending on its location and projection parameters.

Is it possible to automate this process and calculate map rotation angle automatically, for do not find this value manually each time (I would like to create universal composer for all maps via atlas generation menu)?

Best Answer

Below a solution found by @ndawson in the comments of the question. Please feel free to comment and enhance this answer.

Run from the processing toolbox the Oriented minimum bounding box tool onthe map enveloppe grid you already use.

Oriented bounding box tool

It will create a layer that should be quite identical to your original layer. You will find in the attribute table an ANGLE field

OBB fields

You should now be able to use this ANGLE field in the composer to fill in the data defined field for rotation :

Data defined angle

The problem seems to be the angle is not always easy to use because it depends on the way the initial polygons are made. I did a few tests and it depends in which way you have drawn your source polygons. You may have to tweak the attributes values of the ANGLe field accordingly :

(red is original polygons, in black the OMBB tool polygons). I digitalized for the exemple similar polygons is two different ways (going right or left)

OMBB example

To get back the angle value to your original layer, you could use a spatial location join operation.

Related Question