[Qgis-developer] Run Dissolve with selected features

Michael McInnis mmcinnis59 at msn.com
Fri Feb 21 13:10:33 PST 2014


Greetings Devs,
I have a large number of shapefiles I need to process and have had limited success using QGis 2.0.1 with it's python console.
// This works - 
from osgeo import ogr

canvas =
qgis.utils.iface.mapCanvas()

allLayers = canvas.layers()

for i in allLayers: i.selectAll(); print i.name(); print
i.selectedFeatureCount()
// What I can't figure out is how to throw in a selection and then run Dissove on it.
I've tried 
for i in allLayers: i.selectAll(); print i.name(); i.getFeatures(QgsFeatureRequest().QgsExpression('LWFLAG <> "P" '); print i.selectedFeatureCount()andselExp = QgsExpression('LWFLAG <> "P" ')for i in allLayers: i.selectAll(); print i.name(); i.getFeatures(QgsFeatureRequest(selExp); print i.selectedFeatureCount()
andfor i in allLayers: i.selectAll(); print i.name(); i.getFeatures(QgsFeatureRequest('LWFLAG <> "P" ')); print i.selectedFeatureCount()
and several other techniques all to no avail. 
In PseudoCode:
from osgeo import ogrcanvas = qgis.utils.iface.mapCanvas()allLayers = canvas.layers()for i in allLayers:       i.select('LWFLAG <> "P" ');       print i.name();       print i.selectedFeatureCount();      i.dissolve("use sel", i.name() + '_dis', "BLOCKGRP");
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20140221/90487afe/attachment.html>


More information about the Qgis-developer mailing list