Re: [Qgis-developer] Select By Attribute
Thank you so much. I really appreciate your help! Michael McInnis 6033 44th Ave. N.E. Seattle, WA 98115 206 517-4701 Date: Fri, 28 Feb 2014 07:21:21 +0100 From: denis.rouz...@gmail.com To: mmcinni...@msn.com; qgis-developer@lists.osgeo.org Subject: Re: [Qgis-developer] Select By Attribute On 27. 02. 14 18:41, Michael McInnis wrote: Desperately need help doing attribute based selection : How do I select all features in a LAYER that the Field LWFLAG != 'P' Python Console from osgeo import ogr canvas = qgis.utils.iface.mapCanvas() allLayers = canvas.layers() for i in allLayers: i.selectAll(); print i.name(); print i.selectedFeatureCount() for i in allLayers: i.selectAll(); print i.name(); print i.selectedFeatureCount() i.getFeatures(QgsFeatureRequest().setFilterExpression(‘ “LWFLAGS” != \’P\’) ) this is a feature iterator [0], so you need iterate f = QgsFeature() toSelect = [] while i.getFeatures(QgsFeatureRequest().setFilterExpression(‘ “LWFLAGS” != \’P\’) ).nextFeature(f): toSelect.append(f.id()) i.setSelectedFeatures(toSelect) [0] http://qgis.org/api/classQgsFeatureIterator.html exp = QgsExpression(‘LWFLAG <> “P” ’) ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
Re: [Qgis-developer] Select By Attribute
Oh, Man, Thanks ! I can't wait to work with this today ! Michael McInnis 6033 44th Ave. N.E. Seattle, WA 98115 206 517-4701 From: madman...@gmail.com Date: Fri, 28 Feb 2014 16:26:06 +1000 Subject: Re: [Qgis-developer] Select By Attribute To: denis.rouz...@gmail.com CC: mmcinni...@msn.com; qgis-developer@lists.osgeo.org We can make that even easier: toSelect = [] for feature in layer.getFeatures(QgsFeatureRequest(‘“LWFLAGS” != \’P\’')): toSelect.append(feature.id())layer.setSelectedFeatures(toSelect) ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
[Qgis-developer] Select By Attribute
Desperately need help doing attribute based selection : How do I select all features in a LAYER that the Field LWFLAG != 'P' Python Console from osgeo import ogr canvas = qgis.utils.iface.mapCanvas() allLayers = canvas.layers() for i in allLayers: i.selectAll(); print i.name(); print i.selectedFeatureCount() for i in allLayers: i.selectAll(); print i.name(); print i.selectedFeatureCount() i.getFeatures(QgsFeatureRequest().setFilterExpression(‘ “LWFLAGS” != \’P\’) ) exp = QgsExpression(‘LWFLAG <> “P” ’) ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
[Qgis-developer] Still can't select features prior to dissolve
// 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() (In the python Console) Above you use the current layer (i) to i.selectAll(); How do you do a selection using attribute values such as i.selectFeatures("LWFLAG" != 'P') to set the selected features for the dissolve function? qgis.analysis.QgsGeometryAnalyzer.dissolve?4(QgsVectorLayer, QString, bool onlySelectedFeatures=True, int uniqueIdField=-1) -> bool Michael McInnis 6033 44th Ave. N.E. Seattle, WA 98115 206 517-4701 ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
[Qgis-developer] Run Dissolve with selected features
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"); ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer