11

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)?

10
  • 1
    Do you want to rotate the feature so that it is parallel with the edges of the map frame? Could you calculate the azimuth of one of the sides of the feature and use that to rotate it? If it was a line something like rotation = degrees(atan(abs((y1-y2)/(x1-x2)))) would give you an angle in degrees. Then 90 - rotation would align it with the map frame. Jun 29, 2017 at 21:15
  • 2
    Are you using an atlas? If you generate a coverage layer using the "Oriented minimum bounding box" tool, then that layer will include a rotation attribute which can be bound to the map item rotation using data defined properties.
    – ndawson
    Jun 29, 2017 at 23:02
  • @mixedbredie, Yes, I want to rotate my map so that the map boundaries will be parallel to map frame in map canvas. I tried to calculate azimuth, but the problem is that my layer with maps is poligonal and there is no telling that the first point is the left-top vertex or other certain vertex (right-bottom, etc.). So, the angle almost every time doesn't satisfy
    – Jane
    Jun 30, 2017 at 7:39
  • The solution suggested by @ndawson works a treat. Use the new bounding box layer as a hidden coverage layer and everything will be aligned. Jun 30, 2017 at 7:45
  • 1
    Open the Processing Toolbox (Ctrl+Alt+T) and search for "oriented" - you see the tool under QGIS geoalgorithms > Vector general tools. Jun 30, 2017 at 7:59

1 Answer 1

4

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.

3
  • Thank you so much! I've red attentively your detailed answer! But the problem seems to be more complex. I have a layer with all maps and their projections in attribute table for every map. The initial layer with set of maps in WGS84, but when preparing a map, I set the projection in map canvas, taken from attribute table (that differs for every map) and I need a map rotation value in THIS PROJECTION. So,I have to resave every map in their own projection and then run OMBB for the polygon. I tested for some maps, but unseccesfully-rotation angle value differs from calculated via OMBB
    – Jane
    Aug 4, 2017 at 11:28
  • It would be great to calculate rotation angle value in map composer, based on projection formula in attribute table
    – Jane
    Aug 4, 2017 at 11:32
  • Not easy ! I don't see how you could do that in a simple way, especially for rotation angle. There's a way to project data with the function "transform", but i doubt it will work for anything else then coordinates. (Returns the geometry transformed from a source CRS to a destination CRS. Syntax : transform(geom, source_auth_id, dest_auth_id) - Example : geom_to_wkt( transform( $geometry, 'EPSG:2154', 'EPSG:4326' ) )
    – gisnside
    Aug 4, 2017 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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