2

I have a map. I have external data that I can join to the map by name of the feature. The data contains several variables, say abc, def, xyz1, xyz2 and xyz3.

I can display a variable by selecting it in the symbology of the map layer. I created a print layout with a legend which works for all variables xyz*.

How can I (batch) generate separate maps (in png) for all variables xyz*?

1 Answer 1

1

I don't have a solution yet for batch symbolization but if you have symbolized each variable, here is a script that will loop through the selected layers turning each off printing to a pdf & then turning it off. I shouldn't be too difficult to change the pdf to a png.

def printpdfmulti(layoutname):
    selected_layers = qgis.utils.iface.layerTreeView().selectedLayers()
    projectInstance = QgsProject.instance()
    layoutmanager = projectInstance.layoutManager()
    layout = layoutmanager.layoutByName(layoutname) #Layout nameprojectInstance = QgsProject.instance()
    for layer in selected_layers:
        QgsProject.instance().layerTreeRoot().findLayer(layer.id()).setItemVisibilityChecked(True)
        layout.refresh()
        exporter = QgsLayoutExporter(layout)
        filename = "".join(i for i in layer.name() if i not in "\/:*?<>|")
        exporter.exportToPdf("C://data//" + filename + ".pdf", QgsLayoutExporter.PdfExportSettings() )
        QgsProject.instance().layerTreeRoot().findLayer(layer.id()).setItemVisibilityChecked(False)


printpdfmulti("plane_view1")
1
  • I am quite new to qgis. I found that I can create and run this script from the processing toolbox. However, the first line already gives the exception: name 'qgis' is not defined. Btw: I don't have multiple layers. I have only 1 map layer and I need to cycle through some of the columns of the data file (which I think one should select via symbology in the map layer). If there is a better way to generate maps and png for the different columns in my data file, I am open to suggestions. Thanks. Commented Jul 13, 2020 at 14:19

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.