本文整理汇总了Python中qgis.core.QgsExpressionContextUtils.processingAlgorithmScope方法的典型用法代码示例。如果您正苦于以下问题:Python QgsExpressionContextUtils.processingAlgorithmScope方法的具体用法?Python QgsExpressionContextUtils.processingAlgorithmScope怎么用?Python QgsExpressionContextUtils.processingAlgorithmScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsExpressionContextUtils
的用法示例。
在下文中一共展示了QgsExpressionContextUtils.processingAlgorithmScope方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: populateByExpression
# 需要导入模块: from qgis.core import QgsExpressionContextUtils [as 别名]
# 或者: from qgis.core.QgsExpressionContextUtils import processingAlgorithmScope [as 别名]
def populateByExpression(self, adding=False):
"""
Populates the panel using an expression
"""
context = dataobjects.createContext()
expression_context = context.expressionContext()
# use the first row parameter values as a preview during expression creation
params = self.panel.parametersForRow(0, warnOnInvalid=False)
alg_scope = QgsExpressionContextUtils.processingAlgorithmScope(self.panel.alg, params, context)
# create explicit variables corresponding to every parameter
for k, v in params.items():
alg_scope.setVariable(k, v, True)
expression_context.appendScope(alg_scope)
# mark the parameter variables as highlighted for discoverability
highlighted_vars = expression_context.highlightedVariables()
highlighted_vars.extend(list(params.keys()))
expression_context.setHighlightedVariables(highlighted_vars)
dlg = QgsExpressionBuilderDialog(layer=None, context=context.expressionContext())
if adding:
dlg.setExpectedOutputFormat(self.tr('An array of values corresponding to each new row to add'))
if not dlg.exec_():
return
if adding:
exp = QgsExpression(dlg.expressionText())
res = exp.evaluate(expression_context)
if type(res) is not list:
res = [res]
first_row = self.panel.batchRowCount() if self.panel.batchRowCount() > 1 else 0
for row, value in enumerate(res):
self.setRowValue(row + first_row, value, context)
else:
for row in range(self.panel.batchRowCount()):
params = self.panel.parametersForRow(row, warnOnInvalid=False)
# remove previous algorithm scope -- we need to rebuild this completely, using the
# other parameter values from the current row
expression_context.popScope()
alg_scope = QgsExpressionContextUtils.processingAlgorithmScope(self.panel.alg, params, context)
for k, v in params.items():
alg_scope.setVariable(k, v, True)
expression_context.appendScope(alg_scope)
# rebuild a new expression every time -- we don't want the expression compiler to replace
# variables with precompiled values
exp = QgsExpression(dlg.expressionText())
value = exp.evaluate(expression_context)
self.setRowValue(row, value, context)