【问题标题】:QGIS 3 python loop through layers and run algorithmQGIS 3 python循环遍历层并运行算法
【发布时间】:2022-03-11 01:41:54
【问题描述】:

我正在尝试遍历层并在每一层上运行处理算法,但输入错误:

代码

feedback = QgsProcessingFeedback()

# Get current layers
layers = QgsProject.instance().mapLayers().values()

# Loop through layer and run algorithm
for layer in layers:
    processing.run("qgis:pointstopath", {'INPUT': layer, 'ORDER_FIELD': 'name', 'GROUP_FIELD': 'name','OUTPUT': layer+'.gpkg'},feedback)

错误

Traceback (most recent call last):
File "C:\OSGEO4~1\apps\Python37\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 2, in <module>
File "C:/OSGEO4~1/apps/qgis-rel- 
dev/./python/plugins\processing\tools\general.py", line 105, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback,
context)
File "C:/OSGEO4~1/apps/qgis-rel- 
dev/./python/plugins\processing\core\Processing.py", line 183, in 
runAlgorithm
raise QgsProcessingException(msg)
_core.QgsProcessingException: There were errors executing the algorithm.

你如何正确地将输入层从地图解析到算法?

【问题讨论】:

    标签: python gis qgis


    【解决方案1】:

    你不需要使用 'value' 方法。

    正确的方法是layers = QgsProject.instance().mapLayers()

    完整代码为:

    feedback = QgsProcessingFeedback()
    
    # Get current layers
    layers = QgsProject.instance().mapLayers()
    
    # Loop through layer and run algorithm
    for layer in layers:
        processing.run("qgis:pointstopath", {'INPUT': layer, 'ORDER_FIELD': 'name', 'GROUP_FIELD': 'name','OUTPUT': layer+'.gpkg'},feedback)
    

    【讨论】:

      猜你喜欢
      • 2013-09-10
      • 2021-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多