<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <div class="moz-cite-prefix">On 27. 02. 14 18:41, Michael McInnis
      wrote:<br>
    </div>
    <blockquote cite="mid:COL130-W10E6319490CFA67BB60AA4D9830@phx.gbl"
      type="cite">
      <style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
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="MsoNormal">from osgeo import ogr<o:p></o:p></p>
            <p class="MsoNormal">canvas = qgis.utils.iface.mapCanvas()<o:p></o:p></p>
            <p class="MsoNormal">allLayers = canvas.layers()<o:p></o:p></p>
            <p class="MsoNormal">for i in allLayers: i.selectAll();
              print i.name(); print
              i.selectedFeatureCount()<o:p></o:p></p>
            <p class="MsoNormal"><o:p> </o:p></p>
            <p class="MsoNormal">for i in allLayers: i.selectAll();
              print i.name(); print
              i.selectedFeatureCount()<o:p></o:p></p>
            <p class="MsoNormal">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="moz-txt-link-freetext" href="http://qgis.org/api/classQgsFeatureIterator.html">http://qgis.org/api/classQgsFeatureIterator.html</a><br>
    <br>
    <blockquote cite="mid:COL130-W10E6319490CFA67BB60AA4D9830@phx.gbl"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <p class="MsoNormal"><o:p></o:p></p>
            <p class="MsoNormal"><o:p> </o:p></p>
            <p class="MsoNormal"
              style="margin-bottom:0in;margin-bottom:.0001pt"><o:p></o:p></p>
            <div><span style="font-size: 12pt;">exp =
                QgsExpression(‘LWFLAG <> “P” ’)</span> <br>
              <br>
              <br>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Qgis-developer mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/qgis-developer">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a></pre>
    </blockquote>
    <br>
  </body>
</html>