TransWikia.com

Generating maps of several variables

Geographic Information Systems Asked by Hendri Adriaens on December 7, 2020

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

One Answer

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

Answered by Phillip Allen on December 7, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP