Created
October 4, 2016 01:16
-
-
Save gacarrillor/a37615d0fee1d0c11628cbf5ee12f242 to your computer and use it in GitHub Desktop.
"Run" method of a QGIS test plugin to export a composer iterating layers inside a group and making them visible one at a time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run(self): # Run method of a QGIS plugin | |
ruta="/tmp/" | |
# The plugin Maps Printer is required!!! | |
mp = qgis.utils.plugins['MapsPrinter'] | |
composer = self.iface.activeComposers()[0] # We'll only use the first composer | |
extension = '.png' | |
# Get the group to start iterating layers (making only 1 layer visible at a time) | |
group = QgsProject.instance().layerTreeRoot().findGroup( 'DEPTOS' ) | |
for layer in QgsMapLayerRegistry.instance().mapLayers().values(): | |
group.setVisible(0) # Make all the group (and its children) not visible | |
self.iface.legendInterface().setLayerVisible( layer, True ) | |
title = ruta + layer.name() | |
for item in composer.composition().items(): | |
if isinstance(item, QgsComposerLegend): | |
item.updateLegend() # Needed to always get an updated legend | |
break | |
mp.exportCompo( composer, ruta, title, extension ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment