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

kimaidou kimaidou at gmail.com
Tue Nov 9 11:49:03 EST 2010


2010/11/9 Barry Rowlingson <b.rowlingson at lancaster.ac.uk>

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

I love coding : there is never one way to achieve things :)


>
>    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?
>

I don't know :) I tried to have a compact code, so I reused the api method
that seemed simplier, in a spatial approach.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20101109/e4bb0146/attachment.html


More information about the Qgis-developer mailing list