Friday 23 October 2015

python - How to remove all selection from all registered layers using QGIS plugin?


I want to remove all selection from registered layer in QGIS using Python. I tried to clear the map canvas using:


self.iface.mapCanvas().clear()  
self.iface.mapCanvas().refresh()

but the selection persists.



Answer



There is probably a better way to do this, but you can iterate the layers in mapCanvas, and use removeSelection() method.


Something like this:


mc = self.iface.mapCanvas()


For layer in mc.layers():
if layer.type() == layer.VectorLayer:
layer.removeSelection()

mc.refresh()

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...