[Qgis-developer] changeAttributeValue() takes long

Martin Dobias wonder.sk at gmail.com
Tue Feb 15 04:25:37 EST 2011


Hi Raymond

On Mon, Feb 14, 2011 at 11:27 AM, Raymond Nijssen <r.nijssen at terglobo.nl> wrote:
> Hi List,
>
> My python plugin changes attribute values in a table using this line:
>
> lyr.changeAttributeValue(feat.id(),fieldNum,result)
>
> It appears to take approximately 250 ms to run single this line of code.
> That makes my plugin really slow in case I want to change a lot of values,
> which is what I want.
>
> Does anyone know a faster way of doing this?

yes, there's a faster way. You can bypass the editing buffer in
QgsVectorLayer and directly do the changes in underlying
QgsVectorDataProvider - using its changeAttributeValues() method. In
such way you can change many values at once more efficiently. Note:
the changes you do to vector data provider are committed immediately
to the data store (shapefile / database etc.) and cannot be undone.

Regards
Martin


More information about the Qgis-developer mailing list