mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
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.
This commit is contained in:
parent
377cba0b74
commit
86ab3022b5
@ -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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user