1

I'm currently using QGIS 3.10, and have around 60+ coverage layers that each should result in its own atlas pdf-file. All other settings in the print composer would be the same.

As I'm not too familiar with the QGIS API I'm having some trouble finding the right methods to use.

The easiest would be to write a short Python script to run on the interactive Python console in the QGIS GUI, and the logic I would like to implement would be something along the lines of this pseudocode:

make list of coverage layers
initiate print composer
load print composer template from .qpt-file (this is the same for all of the atlases)

for each LAYER in coverage layers
    set coverage layer to LAYER in print composer
    export atlas to pdf with filename LAYER.pdf

1 Answer 1

2

I managed to find a solution to this, not the prettiest code, but gets the job done:

cover_layer_names = ['name1','name2'] # add layer names here

for CV in cover_layer_names:
    cover_layer = QgsProject.instance().mapLayersByName(CV)[0]
    projectInstance = QgsProject.instance()
    layoutmanager = projectInstance.layoutManager()
    layout = layoutmanager.layoutByName("NAME_OF_LAYOUT") #add layout name here
    atlas_obj = layout.atlas()
    atlas_obj.setCoverageLayer(cover_layer)
    file_path = 'FILE PATH HERE' + CV + '.pdf' #insert file path
    QgsLayoutExporter.exportToPdf(layout.atlas(), file_path, QgsLayoutExporter.PdfExportSettings())

Your Answer

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

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