Calling processing tools from Python¶
See QGIS documentation for details.
QGIS processing is available in Python through processing
module. On line 3 we will loop over all available
algorithms. By a simple condition on line 5 only tools
containing a word “buffer” in the name will be printed out.
1 2 3 4 5 | from qgis import processing
for alg in QgsApplication.processingRegistry().algorithms():
name = alg.displayName()
print(alg.id(), "->", name)
|
Let’s select native:buffer tool and execute it by Python code.
1 2 3 4 5 6 7 8 9 | from qgis import processing
processing.run("native:buffer", {
'INPUT': '/home/martin/geodata/gismentors/qgis-data/shp/osm/pozarni_stanice.shp',
'DISTANCE': 10000,
'SEGMENTS': 10,
'DISSOLVE': True,
'OUTPUT': '/tmp/pozarni_stanice_10km.shp'
})
|