<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Thank you so much. I really appreciate your help!<br><br>Michael McInnis
6033 44th Ave. N.E.
Seattle, WA 98115
206 517-4701<br><br><div><hr id="stopSpelling">Date: Fri, 28 Feb 2014 07:21:21 +0100<br>From: denis.rouzaud@gmail.com<br>To: mmcinnis59@msn.com; qgis-developer@lists.osgeo.org<br>Subject: Re: [Qgis-developer] Select By Attribute<br><br>
<br>
<div class="ecxmoz-cite-prefix">On 27. 02. 14 18:41, Michael McInnis
wrote:<br>
</div>
<blockquote cite="mid:COL130-W10E6319490CFA67BB60AA4D9830@phx.gbl">
<style><!--
.ExternalClass .ecxhmmessage P {
padding:0px;
}
.ExternalClass body.ecxhmmessage {
font-size:12pt;
font-family:Calibri;
}
--></style>
<div dir="ltr">Desperately need help doing attribute based
selection :
<div><br>
<div><br>
</div>
<div>How do I select all features in a LAYER that the Field
LWFLAG != 'P'</div>
<div><br>
</div>
<div>Python Console</div>
<div><br>
<div><br>
</div>
<p class="ecxMsoNormal">from osgeo import ogr</p>
<p class="ecxMsoNormal">canvas = qgis.utils.iface.mapCanvas()</p>
<p class="ecxMsoNormal">allLayers = canvas.layers()</p>
<p class="ecxMsoNormal">for i in allLayers: i.selectAll();
print i.name(); print
i.selectedFeatureCount()</p>
<p class="ecxMsoNormal"> </p>
<p class="ecxMsoNormal">for i in allLayers: i.selectAll();
print i.name(); print
i.selectedFeatureCount()</p>
<p class="ecxMsoNormal">i.getFeatures(QgsFeatureRequest().setFilterExpression(‘
“LWFLAGS”
!= \’P\’) )</p>
</div>
</div>
</div>
</blockquote>
this is a feature iterator [0], so you need iterate<br>
<br>
f = QgsFeature()<br>
toSelect = []<br>
while i.getFeatures(QgsFeatureRequest().setFilterExpression(‘
“LWFLAGS” != \’P\’) ).nextFeature(f):<br>
toSelect.append(f.id())<br>
i.setSelectedFeatures(toSelect)<br>
<br>
[0] <a class="ecxmoz-txt-link-freetext" href="http://qgis.org/api/classQgsFeatureIterator.html" target="_blank">http://qgis.org/api/classQgsFeatureIterator.html</a><br>
<br>
<blockquote cite="mid:COL130-W10E6319490CFA67BB60AA4D9830@phx.gbl">
<div dir="ltr">
<div>
<div>
<p class="ecxMsoNormal"></p>
<p class="ecxMsoNormal"> </p>
<p class="ecxMsoNormal" style=""></p>
<div><span style="font-size:12pt;">exp =
QgsExpression(‘LWFLAG <> “P” ’)</span> <br>
<br>
<br>
</div>
</div>
</div>
</div>
<br>
<fieldset class="ecxmimeAttachmentHeader"></fieldset>
<br>
<pre>_______________________________________________
Qgis-developer mailing list
<a class="ecxmoz-txt-link-abbreviated" href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a>
<a class="ecxmoz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a></pre>
</blockquote>
<br></div> </div></body>
</html>