[Qgis-developer] Select By Attribute
Denis Rouzaud
denis.rouzaud at gmail.com
Thu Feb 27 22:21:21 PST 2014
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 at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20140228/f79bd545/attachment.html>
More information about the Qgis-developer
mailing list