1

How do you create a polygon from a QGIS Print Composer or Print Layout map extent (i.e. a polygon that is the exact area shown in a map within a print composer/layout)?

Ultimately I would like to do this for an entire atlas so I would like to do this in as automatic a way as possible, but I would even just be content with a rather manual solution too!

  • 1
    Do you think you could create the polygons first, then use them to drive the atlas pages? – DPSSpatial Aug 21 '18 at 16:32
  • Hmmm, perhaps, but I would probably have to ask another question as to how to do that (hehe), given I need the atlas pages to be all at the same scale, though within a fixed map area size, as well as say the map centre determined by a collection of shapes from the file that creates the atlas in the first place. Also, setting and keeping the same scale is an important part of the project and selecting it, testing with the atlas generation in the Print Layout window, was a relatively simple way of finding the best scale. – guestagain Aug 22 '18 at 1:04
1

A manual solution would be:

In print composer item properties > extents, find the xmin, xmax, ymin and ymax values of the map item.

Use the Geometry by expression tool to create a rectangular polygon. Substitute the actual values into this expression:

make_polygon( geom_from_wkt( 
  'Polygon(( xmax ymax, xmax ymin, xmin ymin, xmin ymax, xmax ymax ))' 
))
  • Thanks, yeah, just gone through and followed a similar process to this using a batch process with the "Create layer from extent" processing algorithm. Took a while but got the job done. I'll upvote the answer but leave the question unanswered in case we be so lucky as to find an automated or less manual solution. – guestagain Aug 22 '18 at 1:07
  • The automated method would be coding this in Python. See the Pyqgis cookbook if you want to attempt that. – csk Aug 22 '18 at 19:18

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.