Create map layout with extent and page size same as a given feature

extentslayoutsprint-composerqgis

I want to create print layouts from a QGIS project, each highlighting some region of interest.
For each of these regions of interest I have a polygon in a vector layer.

So my desired workflow would be:

  1. Select the polygon corresponding to a given region of interest;
  2. Create a new map layout with an extent matching the selected feature extent including page size aspect ratio.

It is important to match not just the extent but also the aspect ratio. It is not enough, for example, to select the feature, zoom to its extent, and then create a layout and click in "set to map canvas extent", because zooming to extent fits the feature to the canvas, and I want the canvas extent (or actually the page size) to be fitted to the feature extent.

Best Answer

Here is a solution to change the map size in the layout based on the bounding box of the polygon. In the comment I do understand that you want the scale will be non variable and only the size of the map will vary in the layout.

Step by step

So first go to atlas, than activate it with the layer of polygon you want to study.

Then select your map in the layout and go to item properties and check controlled by atlas and then choose margin around feature. Activate atlas preview and go through atlas pages to find the right scale.

When you have decided your scale (in my example it is 1000000) you could set your map item to get a size different based on bbox of atlas element. Go to position and size of your map item then set width to be data driven.

enter image description here

The formula should be : bounds_width( @atlas_geometry ) / 1000000 *1000

Do the same for the height of your map : bounds_height( @atlas_geometry ) / 1000000 *1000

NB : I multiplicated by 1000 because the dimension of the map you give is in mm and not in map unit.

The result

I have used French department data, to get map of Loire-atlantique (first) and Paris (second).

enter image description here

Paris with the same scale

enter image description here

Related Question