On Tue, Nov 9, 2010 at 4:22 PM, kimaidou <[email protected]> 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()
        layer.setSelectedFeatures(layerIds(layer))
        return None

where layerIds is:

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

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

Barry
_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to