[Qgis-developer] Select By Attribute

Michael McInnis mmcinnis59 at msn.com
Fri Feb 28 06:50:23 PST 2014


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.rouzaud at gmail.com
To: mmcinnis59 at msn.com; qgis-developer at 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 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/52ac214f/attachment.html>


More information about the Qgis-developer mailing list