Skip to content
Permalink
Browse files

fix indentation and typo

  • Loading branch information
alexbruy committed May 13, 2016
1 parent 730c580 commit 0c8f6f7fbb5821456d7f48493dbb5293bfbfeec2
@@ -128,12 +128,11 @@ def evaluateExpression(self, text):
exp = QgsExpression(text)
if exp.hasParserError():
raise Exception(exp.parserErrorString())
result = exp.evaluate(context)
result = exp.evaluate(context)
if exp.hasEvalError():
raise ValueError(exp.evalErrorString())
return result


def setParamValue(self, param, widget, alg=None):
if isinstance(param, ParameterRaster):
return param.setValue(widget.getValue())
@@ -32,9 +32,13 @@
from PyQt.QtGui import QDialog

from math import log10, floor
from qgis.core import (QgsDataSourceURI, QgsCredentials, QgsExpressionContext,
QgsExpressionContextUtils, QgsExpression, QgsRasterLayer,
QgsExpressionContextScope)
from qgis.core import (QgsDataSourceURI,
QgsCredentials,
QgsExpressionContext,
QgsExpressionContextUtils,
QgsExpression,
QgsRasterLayer,
QgsExpressionContextScope)
from qgis.gui import QgsEncodingFileDialog, QgsExpressionBuilderDialog
from qgis.utils import iface
from processing.tools import dataobjects
@@ -89,12 +93,12 @@ def __init__(self, number, minimum, maximum, isInteger):

def showExpressionsBuilder(self):
context = self.expressionContext()
dlg = QgsExpressionBuilderDialog(None, self.spnValue.text(), self, "generic", context)
dlg.setWindowTitle(self.tr("Expression based input"));
dlg = QgsExpressionBuilderDialog(None, self.spnValue.text(), self, 'generic', context)
dlg.setWindowTitle(self.tr('Expression based input'))
if dlg.exec_() == QDialog.Accepted:
exp = QgsExpression(dlg.expressionText())
if not exp.hasParserError():
result = exp.evaluate(context)
result = exp.evaluate(context)
if not exp.hasEvalError():
try:
self.spnValue.setValue(float(result))
@@ -109,35 +113,35 @@ def expressionContext(self):
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())
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)
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)
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().extent()
processingScope.setVariable("canvasextent_minx", extent.xMinimum())
processingScope.setVariable("canvasextent_miny", extent.yMinimum())
processingScope.setVariable("canvasextent_maxx", extent.xMaximum())
processingScope.setVariable("canvasextent_maxy", extent.yMaximum())
processingScope.setVariable('canvasextent_minx', extent.xMinimum())
processingScope.setVariable('canvasextent_miny', extent.yMinimum())
processingScope.setVariable('canvasextent_maxx', extent.xMaximum())
processingScope.setVariable('canvasextent_maxy', extent.yMaximum())

extent = iface.mapCanvas().fullExtent()
processingScope.setVariable("fullextent_minx", extent.xMinimum())
processingScope.setVariable("fullextent_miny", extent.yMinimum())
processingScope.setVariable("fullextent_maxx", extent.xMaximum())
processingScope.setVariable("fullextent_maxy", extent.yMaximum())
processingScope.setVariable('fullextent_minx', extent.xMinimum())
processingScope.setVariable('fullextent_miny', extent.yMinimum())
processingScope.setVariable('fullextent_maxx', extent.xMaximum())
processingScope.setVariable('fullextent_maxy', extent.yMaximum())
context.appendScope(processingScope)
return context

@@ -33,8 +33,12 @@
from qgis.PyQt.QtWidgets import QDialog, QMenu, QAction, QFileDialog
from qgis.PyQt.QtGui import QCursor
from qgis.gui import QgsEncodingFileDialog, QgsExpressionBuilderDialog
from qgis.core import QgsDataSourceURI, QgsCredentials, QgsExpressionContext,\
QgsExpressionContextUtils, QgsExpression, QgsExpressionContextScope
from qgis.core import (QgsDataSourceURI,
QgsCredentials,
QgsExpressionContext,
QgsExpressionContextUtils,
QgsExpression,
QgsExpressionContextScope)

from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.outputs import OutputVector
@@ -107,8 +111,8 @@ def selectOutput(self):
popupMenu.exec_(QCursor.pos())

def showExpressionsBuilder(self):
dlg = QgsExpressionBuilderDialog(None, self.leText.text(), self, "generic", self.expressionContext())
dlg.setWindowTitle(self.tr("Expression based output"));
dlg = QgsExpressionBuilderDialog(None, self.leText.text(), self, 'generic', self.expressionContext())
dlg.setWindowTitle(self.tr('Expression based output'))
if dlg.exec_() == QDialog.Accepted:
self.leText.setText(dlg.expressionText())

@@ -117,8 +121,8 @@ def expressionContext(self):
context.appendScope(QgsExpressionContextUtils.globalScope())
context.appendScope(QgsExpressionContextUtils.projectScope())
processingScope = QgsExpressionContextScope()
for param in self.ag.parameters:
processingScope.setVariable("%s_value" % param.name, "")
for param in self.alg.parameters:
processingScope.setVariable('%s_value' % param.name, '')
context.appendScope(processingScope)
return context

@@ -227,7 +231,7 @@ def getValue(self):
context = self.expressionContext()
exp = QgsExpression(fileName)
if not exp.hasParserError():
result = exp.evaluate(context)
result = exp.evaluate(context)
if not exp.hasEvalError():
fileName = result
if fileName.strip() in ['', self.SAVE_TO_TEMP_FILE]:

0 comments on commit 0c8f6f7

Please sign in to comment.
You can’t perform that action at this time.