[Qgis-developer] Qgis Api - select all features of a vector layer

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Tue Nov 9 11:46:19 EST 2010

On Tue, Nov 9, 2010 at 4:22 PM, kimaidou <kimaidou at gmail.com> wrote:
> Hi again
> Still working on my python plugin...
> I need to simply select all the features of a chosen vector layer. In
> QgsVectorLayer api, there is no method "selectAllFeatures()"
> So I use this piece of code to achieve it
> http://osgeo.pastebin.com/Ma9DxgKR

 That's an interesting approach! My selectplus plugin has a 'select
all' function which does this:

    def doit(self):
        layer = self.iface.mapCanvas().currentLayer()
        return None

where layerIds is:

def layerIds(layer):
    ids = []
    p = layer.dataProvider()
    allAttrs = p.attributeIndexes()
    f = QgsFeature()
    while p.nextFeature(f):
    return ids

Your rectangle overlay should be pretty quick, but maybe my collecting
all the feature IDs is quicker?


More information about the Qgis-developer mailing list