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


Python ScriptAlgorithm.initAlgorithm方法代码示例

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


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

示例1: check_algorithm

# 需要导入模块: from processing.script.ScriptAlgorithm import ScriptAlgorithm [as 别名]
# 或者: from processing.script.ScriptAlgorithm.ScriptAlgorithm import initAlgorithm [as 别名]
    def check_algorithm(self, name, defs):
        """
        Will run an algorithm definition and check if it generates the expected result
        :param name: The identifier name used in the test output heading
        :param defs: A python dict containing a test algorithm definition
        """
        self.vector_layer_params = {}
        QgsProject.instance().removeAllMapLayers()

        params = self.load_params(defs['params'])

        if defs['algorithm'].startswith('script:'):
            filePath = os.path.join(processingTestDataPath(), 'scripts', '{}.py'.format(defs['algorithm'][len('script:'):]))
            alg = ScriptAlgorithm(filePath)
            alg.initAlgorithm()
        else:
            print('Running alg: "{}"'.format(defs['algorithm']))
            alg = QgsApplication.processingRegistry().createAlgorithmById(defs['algorithm'])

        parameters = {}
        if isinstance(params, list):
            for param in zip(alg.parameterDefinitions(), params):
                parameters[param[0].name()] = param[1]
        else:
            for k, p in list(params.items()):
                parameters[k] = p

        for r, p in list(defs['results'].items()):
            if not 'in_place_result' in p or not p['in_place_result']:
                parameters[r] = self.load_result_param(p)

        expectFailure = False
        if 'expectedFailure' in defs:
            exec(('\n'.join(defs['expectedFailure'][:-1])), globals(), locals())
            expectFailure = eval(defs['expectedFailure'][-1])

        # ignore user setting for invalid geometry handling
        context = QgsProcessingContext()
        context.setProject(QgsProject.instance())

        if 'skipInvalid' in defs and defs['skipInvalid']:
            context.setInvalidGeometryCheck(QgsFeatureRequest.GeometrySkipInvalid)

        feedback = QgsProcessingFeedback()

        if expectFailure:
            try:
                results, ok = alg.run(parameters, context, feedback)
                self.check_results(results, context, defs['params'], defs['results'])
                if ok:
                    raise _UnexpectedSuccess
            except Exception:
                pass
        else:
            results, ok = alg.run(parameters, context, feedback)
            self.assertTrue(ok, 'params: {}, results: {}'.format(parameters, results))
            self.check_results(results, context, defs['params'], defs['results'])
开发者ID:Jacory,项目名称:QGIS,代码行数:59,代码来源:AlgorithmsTestBase.py


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