当前位置: 首页>>代码示例>>Python>>正文


Python QgsExpressionContextUtils.globalScope方法代码示例

本文整理汇总了Python中qgis.core.QgsExpressionContextUtils.globalScope方法的典型用法代码示例。如果您正苦于以下问题:Python QgsExpressionContextUtils.globalScope方法的具体用法?Python QgsExpressionContextUtils.globalScope怎么用?Python QgsExpressionContextUtils.globalScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.core.QgsExpressionContextUtils的用法示例。


在下文中一共展示了QgsExpressionContextUtils.globalScope方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: processAlgorithm

# 需要导入模块: from qgis.core import QgsExpressionContextUtils [as 别名]
# 或者: from qgis.core.QgsExpressionContextUtils import globalScope [as 别名]
    def processAlgorithm(self, progress):
        ns = {}
        ns["progress"] = progress
        ns["scriptDescriptionFile"] = self.descriptionFile

        for param in self.parameters:
            ns[param.name] = param.value

        for out in self.outputs:
            ns[out.name] = out.value

        variables = re.findall("@[a-zA-Z0-9_]*", self.script)
        script = "import processing\n"
        script += self.script

        context = QgsExpressionContext()
        context.appendScope(QgsExpressionContextUtils.globalScope())
        context.appendScope(QgsExpressionContextUtils.projectScope())
        for var in variables:
            varname = var[1:]
            if context.hasVariable(varname):
                script = script.replace(var, context.variable(varname))
            else:
                ProcessingLog.addToLog(ProcessingLog.LOG_WARNING, "Cannot find variable: %s" % varname)

        exec((script), ns)
        for out in self.outputs:
            out.setValue(ns[out.name])
开发者ID:havatv,项目名称:QGIS,代码行数:30,代码来源:ScriptAlgorithm.py

示例2: processAlgorithm

# 需要导入模块: from qgis.core import QgsExpressionContextUtils [as 别名]
# 或者: from qgis.core.QgsExpressionContextUtils import globalScope [as 别名]
    def processAlgorithm(self, progress):
        layer = layer = dataobjects.getObjectFromUri(self.getParameterValue(self.INPUT))

        expression = self.getParameterValue(self.EXPRESSION)
        qExp = QgsExpression(expression)
        if qExp.hasParserError():
            raise GeoAlgorithmExecutionException(qExp.parserErrorString())

        writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
            layer.fields(), layer.wkbType(), layer.crs())

        context = QgsExpressionContext()
        context.appendScope(QgsExpressionContextUtils.globalScope())
        context.appendScope(QgsExpressionContextUtils.projectScope())
        context.appendScope(QgsExpressionContextUtils.layerScope(layer))

        count = layer.featureCount()
        step = 100.0 / count if count else 1

        request = QgsFeatureRequest(qExp, context)

        for current, f in enumerate(layer.getFeatures(request)):
            writer.addFeature(f)
            progress.setPercentage(int(current * step))

        del writer
开发者ID:DHI-GRAS,项目名称:ESA_Processing,代码行数:28,代码来源:ExtractByExpression.py

示例3: processAlgorithm

# 需要导入模块: from qgis.core import QgsExpressionContextUtils [as 别名]
# 或者: from qgis.core.QgsExpressionContextUtils import globalScope [as 别名]
    def processAlgorithm(self, parameters, context, feedback):
        ns = {}
        ns['feedback'] = feedback
        ns['scriptDescriptionFile'] = self.descriptionFile
        ns['context'] = context

        for param in self.parameterDefinitions():
            ns[param.name] = parameters[param.name()]

        for out in self.outputs:
            ns[out.name] = out.value

        variables = re.findall('@[a-zA-Z0-9_]*', self.script)
        script = 'import processing\n'
        script += self.script

        context = QgsExpressionContext()
        context.appendScope(QgsExpressionContextUtils.globalScope())
        context.appendScope(QgsExpressionContextUtils.projectScope(QgsProject.instance()))
        for var in variables:
            varname = var[1:]
            if context.hasVariable(varname):
                script = script.replace(var, context.variable(varname))
            else:
                QgsMessageLog.logMessage(self.tr('Cannot find variable: {0}').format(varname), self.tr('Processing'), QgsMessageLog.WARNING)

        exec((script), ns)
        for out in self.outputs:
            out.setValue(ns[out.name])
开发者ID:rskelly,项目名称:QGIS,代码行数:31,代码来源:ScriptAlgorithm.py

示例4: processAlgorithm

# 需要导入模块: from qgis.core import QgsExpressionContextUtils [as 别名]
# 或者: from qgis.core.QgsExpressionContextUtils import globalScope [as 别名]
    def processAlgorithm(self, progress):
        layer = dataobjects.getObjectFromUri(
            self.getParameterValue(self.INPUT_LAYER))

        geometry_type = self.getParameterValue(self.OUTPUT_GEOMETRY)
        wkb_type = None
        if geometry_type == 0:
            wkb_type = QgsWkbTypes.Polygon
        elif geometry_type == 1:
            wkb_type = QgsWkbTypes.LineString
        else:
            wkb_type = QgsWkbTypes.Point
        if self.getParameterValue(self.WITH_Z):
            wkb_type = QgsWkbTypes.addZ(wkb_type)
        if self.getParameterValue(self.WITH_M):
            wkb_type = QgsWkbTypes.addM(wkb_type)

        writer = self.getOutputFromName(
            self.OUTPUT_LAYER).getVectorWriter(
                layer.fields(),
                wkb_type,
                layer.crs())

        expression = QgsExpression(self.getParameterValue(self.EXPRESSION))
        if expression.hasParserError():
            raise GeoAlgorithmExecutionException(expression.parserErrorString())

        exp_context = QgsExpressionContext()
        exp_context.appendScope(QgsExpressionContextUtils.globalScope())
        exp_context.appendScope(QgsExpressionContextUtils.projectScope())
        exp_context.appendScope(QgsExpressionContextUtils.layerScope(layer))

        if not expression.prepare(exp_context):
            raise GeoAlgorithmExecutionException(
                self.tr('Evaluation error: %s' % expression.evalErrorString()))

        features = vector.features(layer)
        total = 100.0 / len(features)
        for current, input_feature in enumerate(features):
            output_feature = input_feature

            exp_context.setFeature(input_feature)
            value = expression.evaluate(exp_context)
            if expression.hasEvalError():
                raise GeoAlgorithmExecutionException(
                    self.tr('Evaluation error: %s' % expression.evalErrorString()))

            if not value:
                output_feature.setGeometry(QgsGeometry())
            else:
                if not isinstance(value, QgsGeometry):
                    raise GeoAlgorithmExecutionException(
                        self.tr('{} is not a geometry').format(value))
                output_feature.setGeometry(value)

            writer.addFeature(output_feature)
            progress.setPercentage(int(current * total))

        del writer
开发者ID:drnextgis,项目名称:QGIS,代码行数:61,代码来源:GeometryByExpression.py

示例5: initContext

# 需要导入模块: from qgis.core import QgsExpressionContextUtils [as 别名]
# 或者: from qgis.core.QgsExpressionContextUtils import globalScope [as 别名]
 def initContext(self):
     exp_context = self.builder.expressionContext()
     exp_context.appendScope(QgsExpressionContextUtils.globalScope())
     exp_context.appendScope(QgsExpressionContextUtils.projectScope())
     exp_context.appendScope(QgsExpressionContextUtils.layerScope(self.layer))
     exp_context.lastScope().setVariable("row_number", 1)
     exp_context.setHighlightedVariables(["row_number"])
     self.builder.setExpressionContext(exp_context)
开发者ID:DHI-GRAS,项目名称:ESA_Processing,代码行数:10,代码来源:FieldsCalculatorDialog.py

示例6: _expressionContext

# 需要导入模块: from qgis.core import QgsExpressionContextUtils [as 别名]
# 或者: from qgis.core.QgsExpressionContextUtils import globalScope [as 别名]
def _expressionContext(alg):
    context = QgsExpressionContext()
    context.appendScope(QgsExpressionContextUtils.globalScope())
    context.appendScope(QgsExpressionContextUtils.projectScope())
    processingScope = QgsExpressionContextScope()
    for param in alg.parameters:
        processingScope.setVariable('%s_value' % param.name, '')
    context.appendScope(processingScope)
    return context
开发者ID:spono,项目名称:QGIS,代码行数:11,代码来源:outputs.py

示例7: expressionContext

# 需要导入模块: from qgis.core import QgsExpressionContextUtils [as 别名]
# 或者: from qgis.core.QgsExpressionContextUtils import globalScope [as 别名]
 def expressionContext(self):
     context = QgsExpressionContext()
     context.appendScope(QgsExpressionContextUtils.globalScope())
     context.appendScope(QgsExpressionContextUtils.projectScope())
     processingScope = QgsExpressionContextScope()
     for param in self.alg.parameters:
         processingScope.setVariable("%s_value" % param.name, "")
     context.appendScope(processingScope)
     return context
开发者ID:CS-SI,项目名称:QGIS,代码行数:11,代码来源:OutputSelectionPanel.py


注:本文中的qgis.core.QgsExpressionContextUtils.globalScope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。