Bug report #12629

Vector Layer TranslateFeatures performance (2.8.1 vs 1.8.0)

Added by jopan - over 9 years ago. Updated over 5 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Python plugins
Affected QGIS version:2.8.1 Regression?:No
Operating System:Linux 3.2.0-27-generic #43-Ubuntu SMP x86_64 Easy fix?:No
Pull Request or Patch supplied:No Resolution:end of life
Crashes QGIS or corrupts data:No Copied to github as #:20744

Description

I developed a plugin for Qgis version 1.8.0 that translates a vector layer with the simple following code:

delta_x = 0.1
delta_y = 0.3
vlayer = iface.activeLayer()
for fid in range(vlayer.featureCount()):
  vlayer.translateFeature(fid, delta_x, delta_y)

then converted for 2.8.1 with the following code:

delta_x = 0.1
delta_y = 0.3
vlayer = iface.activeLayer()
for f in vlayer.getFeatures():
  fid = f.id()
  vlayer.translateFeature(fid, delta_x, delta_y)

I experience big performance issues in 2.8.1.
Qgis 1.8.0 performs the translation of the attached ShapeFile in about 4 seconds both for the first translation and the following ones.
Qgis 2.8.1 performs the same translation in about 4 minutes for the first translation and in 20 seconds for the following ones.

The layer loading time is the same for both versions (about 1 second).

I cannot understand the reason of this loss of performance.
I'm available to further test my installations or provide any other data.

The system on which I'm running both Qgis versions is:

Distributor ID: Ubuntu
Description: Ubuntu 12.04.3 LTS
Release: 12.04
Codename: precise

Linux 3.2.0-27-generic #43-Ubuntu SMP Fri Jul 6 14:25:57 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Thank you very much.

test.tar.gz (1.46 MB) jopan -, 2015-04-23 02:23 AM

History

#1 Updated by Giovanni Manghi over 9 years ago

  • Category set to Python plugins
  • Status changed from Open to Feedback

please post this question also on the developers mailing list.

#2 Updated by Matthias Kuhn over 9 years ago

Can you check if it helps to group it in a single undo command.
I.e. compare the result of the following two snippets

Grouped:

from timeit import *

def funct():
    vlayer = iface.activeLayer()
    u = QgsVectorLayerEditUtils( vlayer )
    vlayer.beginEditCommand( 'Translate' )
    for f in vlayer.getFeatures():
        f.id()
        u.translateFeature(fid, delta_x, delta_y)
    vlayer.endEditCommand()

t = Timer(stmt=funct)

print t.timeit(number = 5 )

Ungrouped:

from timeit import *

def funct():
    vlayer = iface.activeLayer()
    u = QgsVectorLayerEditUtils( vlayer )
    for f in vlayer.getFeatures():
        f.id()
        u.translateFeature(fid, delta_x, delta_y)

t = Timer(stmt=funct)

print t.timeit(number = 5 )

#3 Updated by Matthias Kuhn over 9 years ago

You can also play with the following snippet:

vlayer.getFeatures( QgsFeatureRequest().setSubsetOfAttributes([]) )

#4 Updated by jopan - over 9 years ago

Firstly I posted this question on the Qgis developers mailing list.

Secondly I tried to play with "grouped"/"ungrouped" and "QgsFeatureRequest().setSubsetOfAttributes([])" but the situation didn't change. The first translation in version 2.8.1 still lasted 4 minutes.

#5 Updated by Giovanni Manghi almost 9 years ago

  • Status changed from Feedback to Open

#6 Updated by Giovanni Manghi over 7 years ago

  • Regression? set to No
  • Easy fix? set to No

#7 Updated by Giovanni Manghi over 5 years ago

  • Resolution set to end of life
  • Status changed from Open to Closed

Also available in: Atom PDF