Skip to content

Commit

Permalink
processing extended
Browse files Browse the repository at this point in the history
  • Loading branch information
landam committed Oct 28, 2023
1 parent 41581ee commit f45f852
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
6 changes: 5 additions & 1 deletion _static/scripts/processing_buffer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from qgis import processing

output = '/tmp/pozarni_stanice_10km.shp'
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'
'OUTPUT': output
})

layer = QgsVectorLayer(output, os.path.basename(output), 'ogr')
QgsProject.instance().addMapLayer(layer)
9 changes: 6 additions & 3 deletions _static/scripts/processing_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from qgis import processing

for alg in QgsApplication.processingRegistry().algorithms():
name = alg.displayName()
if 'buffer' in name:
print(alg.id(), "->", name)
if 'buffer' in alg.id():
print(alg.id(), "->", alg.displayName())

if alg.id() == 'native:buffer':
for p in alg.parameterDefinitions():
print(p.name(), p.description())
23 changes: 20 additions & 3 deletions python/processing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,36 @@ for details.

QGIS processing is available in Python through ``processing``
module. On line :lcode:`3` we will loop over all available
algorithms. By a simple condition on line :lcode:`5` only tools
algorithms. By a simple condition on line :lcode:`4` only tools
containing a word "buffer" in the name will be printed out.

.. literalinclude:: ../_static/scripts/processing_search.py
:language: python
:linenos:
:emphasize-lines: 1, 3, 5
:lines: 1-5
:emphasize-lines: 1, 3, 4

List parameters for selected algorithm:

.. literalinclude:: ../_static/scripts/processing_search.py
:language: python
:linenos:
:lines: 7-9
:emphasize-lines: 2

Let's select `native:buffer
<https://docs.qgis.org/3.28/en/docs/user_manual/processing_algs/qgis/vectorgeometry.html#qgisbuffer>`__
tool and execute it by Python code.

.. literalinclude:: ../_static/scripts/processing_buffer.py
:language: python
:lines: 1-10
:linenos:
:emphasize-lines: 3
:emphasize-lines: 4

Newly created layer can be added into layer tree (see next section for :doc:`pyqgis_intro`):

.. literalinclude:: ../_static/scripts/processing_buffer.py
:language: python
:lines: 12-13
:linenos:

0 comments on commit f45f852

Please sign in to comment.