0
import sys
sys.path.append("c:\\osgeo4w64\\app\qgis\\pyto\\plugins")
    
import processing, os,glob
layer1 = QgsVectorLayer(layer1ShpFilePath, "layer1", "ogr")
layer2 = QgsVectorLayer(layer2ShpFilePath, "layer2", "ogr")
        
params = {
     'INPUT': layer1,
     'OVERLAY': layer2,
     'OUTPUT': "TEST.shp"
}
        
intersectLayer = processing.run("saga:intersect", params)

我想使用 pyQgis 找出 2 个矢量图层之间的相交多边形,但我总是遇到错误 AttributeError: module 'processing' has no attribute 'run' 谁能帮帮我?我正在窗口机器上使用QGis编写python,我已经将基本的QGIS路径添加到环境变量中,但是我不确定是否需要将SAGA包添加到窗口环境变量中。

4

1 回答 1

0

had the same problem - it maybe because your import path in sys.path.append is incorrect (I see a typo in your post).

To check your installation you can type sys.path in qgis console:
Python Console
Use iface to access QGIS API interface or Type help(iface) for more info
Security warning: typing commands from an untrusted source can harm your computer
import sys
sys.path
['/usr/share/qgis/python', '/home/<username>/.local/share/QGIS/QGIS3/profiles/default/python', '/home/<username>/.local/share/QGIS/QGIS3/profiles/default/python/plugins', '/usr/share/qgis/python/plugins', '/usr/lib64/python39.zip', '/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload', '/home/<username>/.local/lib/python3.9/site-packages', '/usr/local/lib/python3.9/site-packages', '/usr/lib64/python3.9/site-packages', '/usr/lib/python3.9/site-packages', '/home/<username>/.local/share/QGIS/QGIS3/profiles/default/python']

All the best,

于 2021-06-13T21:02:02.260 回答