Skip to content

Commit

Permalink
Remove layer extent and statistic variables from processing contexts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nyalldawson committed Nov 22, 2016
1 parent 377cba0 commit 86ab302
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions python/plugins/processing/core/parameters.py
Expand Up @@ -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())
Expand Down

0 comments on commit 86ab302

Please sign in to comment.