Thanks for this answer

2010/11/9 Carson Farmer <[email protected]>

> ...and with the newer PyQGIS API, we can do things even more Pythonically:
>
>
Is the new api usable from 1.5, or should I wait for the next version ?


> def layerIds(layer):
>     layer.select([]) # we don't actually need the attributes
>    ids = [feat.id() for feat in layer]
>     return ids
>
> Obviously you could skip the step of creating the layerIds function,
> and then you'd reduce the entire thing down to:
>
> layer = self.iface.mapCanvas().currentLayer() # or however else you
> get the layer
> layer.select([]) # we don't actually need the attributes
> layer.setSelectedFeatures([feat.id() for feat in layer]) # select all
> the feature ids
>

Yes , it is more concise and the list comprehension is much more pythonistic
;)
I was on other php projects, and lost my python :)


>
> My guess is that this would be quite a bit faster than boundingbox
> method, especially because select(QgsRectangle, bool) actually
> contains this:
>
> QgsFeature f;
> while ( nextFeature( f ) )
> {
>  select( f.id(), false );
> }
>
>
Ok. Thanks again !

> whereas setSelectedFeatures is more direct.
>
> Carson
_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to