Skip to content

Commit 86ab302

Browse files
committed
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.
1 parent 377cba0 commit 86ab302

File tree

1 file changed

+0
-20
lines changed

1 file changed

+0
-20
lines changed

python/plugins/processing/core/parameters.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,6 @@ def _expressionContext():
7676
context.appendScope(QgsExpressionContextUtils.mapSettingsScope(iface.mapCanvas().mapSettings()))
7777

7878
processingScope = QgsExpressionContextScope()
79-
layers = dataobjects.getAllLayers()
80-
for layer in layers:
81-
name = layer.name()
82-
processingScope.setVariable('%s_minx' % name, layer.extent().xMinimum())
83-
processingScope.setVariable('%s_miny' % name, layer.extent().yMinimum())
84-
processingScope.setVariable('%s_maxx' % name, layer.extent().xMaximum())
85-
processingScope.setVariable('%s_maxy' % name, layer.extent().yMaximum())
86-
if isinstance(layer, QgsRasterLayer):
87-
cellsize = (layer.extent().xMaximum()
88-
- layer.extent().xMinimum()) / layer.width()
89-
processingScope.setVariable('%s_cellsize' % name, cellsize)
90-
91-
layers = dataobjects.getRasterLayers()
92-
for layer in layers:
93-
for i in range(layer.bandCount()):
94-
stats = layer.dataProvider().bandStatistics(i + 1)
95-
processingScope.setVariable('%s_band%i_avg' % (name, i + 1), stats.mean)
96-
processingScope.setVariable('%s_band%i_stddev' % (name, i + 1), stats.stdDev)
97-
processingScope.setVariable('%s_band%i_min' % (name, i + 1), stats.minimumValue)
98-
processingScope.setVariable('%s_band%i_max' % (name, i + 1), stats.maximumValue)
9979

10080
extent = iface.mapCanvas().fullExtent()
10181
processingScope.setVariable('fullextent_minx', extent.xMinimum())

0 commit comments

Comments
 (0)