From 86ab3022b552c07709d98f7dbf092330938587eb Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 16 Nov 2016 10:25:07 +1000 Subject: [PATCH] Remove layer extent and statistic variables from processing contexts These variables take a lot of time to calculate and cause lots of lengthy hangs in processing. (Eg add some moderately large rasters to a project, then try to run any processing algorithm and QGIS will freeze). The layer extent can already be used in expressions via the layer_property function, which only evalutes the extent if required and only for layers it is used for. The band stats for raster layers should be moved to a band_statistic function in core which behaves the same way. --- python/plugins/processing/core/parameters.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/python/plugins/processing/core/parameters.py b/python/plugins/processing/core/parameters.py index 706dd16d18b..acc2f614935 100644 --- a/python/plugins/processing/core/parameters.py +++ b/python/plugins/processing/core/parameters.py @@ -76,26 +76,6 @@ def _expressionContext(): context.appendScope(QgsExpressionContextUtils.mapSettingsScope(iface.mapCanvas().mapSettings())) processingScope = QgsExpressionContextScope() - layers = dataobjects.getAllLayers() - for layer in layers: - name = layer.name() - processingScope.setVariable('%s_minx' % name, layer.extent().xMinimum()) - processingScope.setVariable('%s_miny' % name, layer.extent().yMinimum()) - processingScope.setVariable('%s_maxx' % name, layer.extent().xMaximum()) - processingScope.setVariable('%s_maxy' % name, layer.extent().yMaximum()) - if isinstance(layer, QgsRasterLayer): - cellsize = (layer.extent().xMaximum() - - layer.extent().xMinimum()) / layer.width() - processingScope.setVariable('%s_cellsize' % name, cellsize) - - layers = dataobjects.getRasterLayers() - for layer in layers: - for i in range(layer.bandCount()): - stats = layer.dataProvider().bandStatistics(i + 1) - processingScope.setVariable('%s_band%i_avg' % (name, i + 1), stats.mean) - processingScope.setVariable('%s_band%i_stddev' % (name, i + 1), stats.stdDev) - processingScope.setVariable('%s_band%i_min' % (name, i + 1), stats.minimumValue) - processingScope.setVariable('%s_band%i_max' % (name, i + 1), stats.maximumValue) extent = iface.mapCanvas().fullExtent() processingScope.setVariable('fullextent_minx', extent.xMinimum())