22.5. Die Grafische Modellierung¶
Der Grafische Modellierer ermöglicht es Ihnen, komplexe Modelle über eine einfache und leicht zu bedienende Schnittstelle zu erstellen. Wenn Sie mit einem GIS arbeiten, sind die meisten Analyseoperationen nicht isoliert, sondern Teil einer Kette von Operationen. Mit dem grafischen Modellierer kann diese Kette von Operationen in einen einzigen Prozess verpackt werden, so dass sie später bequem mit einem anderen Satz von Eingaben ausgeführt werden kann. Unabhängig davon, wie viele Schritte und verschiedene Algorithmen es umfasst, wird ein Modell als ein einziger Algorithmus ausgeführt, was Zeit und Mühe spart.
Der grafische Modellierer kann über das Menü Verarbeitung geöffnet werden (
).The modeler has a working canvas where the structure of the model and the workflow it represents are shown. The left part of the window is a section with five panels that can be used to add new elements to the model:
Model Properties
: you can specify the name of the model and the group that will contain itInputs
: all the inputs that will shape your modelAlgorithms
: the Processing algorithms availableVariables
: you can also define variables that will only be available in the Processing ModelerUndo History
: this panel will register everything that happens in the modeler, making it easy to cancel things you did wrong.

Abb. 22.18 Modellierung¶
Creating a model involves two basic steps:
Definition of necessary inputs. These inputs will be added to the parameters window, so the user can set their values when executing the model. The model itself is an algorithm, so the parameters window is generated automatically as for all algorithms available in the Processing framework.
Definition des Arbeitsablaufs. Der Arbeitsablauf wird definiert, indem Algorithmen hinzugefügt werden. In diesen wird festgelegt, wie sie die definierten Eingaben oder die von anderen Algorithmen im Modell erzeugten Ausgaben verwenden.
22.5.1. Definition von Eingaben¶
The first step is to define the inputs for the model. The following elements are found in the Inputs panel on the left side of the modeler window:
Authentifikationskonfiguration
Boolean
Farbe
Connection Name
Coordinate Operation
KBS
Database Schema
Database Table
Datetime
Abstand
Aufzählung
Ausdruck
Ausdehnung
Fields Aggregate
Feldabbildung
Datei/Ordner
Kartenlayer
Map Theme
Matrix
Mesh Layer
Mehrfacheingabe
Number
Punkt
Drucklayout
Drucklayout Element
Bereich
Rasterkanal
Rasterlayer
Maßstab
Zeichenkette
Vektorobjekte
Vektorfeld
Vektorlayer
Vector Tile Writer Layers
Bemerkung
Hovering with the mouse over the inputs will show a tooltip with additional information.
When double-clicking on an element, a dialog is shown that lets you define its characteristics. Depending on the parameter, the dialog will contain at least one element (the description, which is what the user will see when executing the model). For example, when adding a numerical value, as can be seen in the next figure, in addition to the description of the parameter, you have to set a default value and the range of valid values.

Abb. 22.19 Definition der Modellparameter¶
You can define your input as mandatory for your model by checking the
Mandatory
option and by checking the
Advanced
checkbox you can set the input to be within the Advanced
section. This is
particularly useful when the model has many parameters and some of them are not
trivial, but you still want to choose them.
The Comments
tab allows you to tag the input with more information,
to better describe
the parameter. Comments are visible only in the modeler canvas and not in the
final algorithm dialog.
For each added input, a new element is added to the modeler canvas.

Abb. 22.20 Modellparameter¶
You can also add inputs by dragging the input type from the list and dropping it at the position where you want it in the modeler canvas. If you want to change a parameter of an existing input, just double click on it, and the same dialog will pop up.
22.5.2. Definition des Arbeitsablaufs¶
In the following example we will add two inputs and two algorithms. The aim of
the model is to copy the elevation values from a DEM raster layer to a line layer
using the Drape
algorithm, and then calculate the total ascent of the line
layer using the Climb Along Line
algorithm.
In the Inputs tab, choose the two inputs as Vector Layer
for the line and
Raster Layer
for the DEM.
We are now ready to add the algorithms to the workflow.
Algorithms can be found in the Algorithms panel, grouped much in the same way as they are in the Processing toolbox.

Abb. 22.21 Modell-Eingaben¶
To add an algorithm to a model, double-click on its name or drag and
drop it, just like for inputs. As for the inputs you can change the description
of the algorithm and add a comment.
When adding an algorithm, an execution dialog will appear, with a content similar
to the one found in the execution panel that is shown when executing the
algorithm from the toolbox.
The following picture shows both the Drape (set Z value from raster)
and the
Climb along line
algorithm dialogs.

Abb. 22.22 Modell-Algorithmus-Parameter¶
As you can see there are some differences.
You have four choices to define the algorithm inputs:
Value
: allows you to set the parameter from a loaded layer in the QGIS project or to browse a layer from a folderPre-calculated Value
: with this option you can open the Expression Builder and define your own expression to fill the parameter. Model inputs together with some other layer statistics are available as variables and are listed at the top of the Search dialog of the Expression BuilderModel Input
: choose this option if the parameter comes from an input of the model you have defined. Once clicked, this option will list all the suitable inputs for the parameterAlgorithm Output
: is useful when the input parameter of an algorithm is an output of another algorithm
Algorithm outputs have the addditional
Model Output
option that makes the output of the algorithm available in the model.
If a layer generated by the algorithm is only to be used as input to another algorithm, don’t edit that text box.
In the following picture you can see the two input parameters defined as
Model Input
and the temporary output layer:

Abb. 22.23 Algorithm Input and Output parameters¶
In all cases, you will find an additional parameter named Dependencies that is not available when calling the algorithm from the toolbox. This parameter allows you to define the order in which algorithms are executed, by explicitly defining one algorithm as a parent of the current one. This will force the parent algorithm to be executed before the current one.
When you use the output of a previous algorithm as the input of your algorithm, that implicitly sets the previous algorithm as parent of the current one (and places the corresponding arrow in the modeler canvas). However, in some cases an algorithm might depend on another one even if it does not use any output object from it (for instance, an algorithm that executes a SQL sentence on a PostGIS database and another one that imports a layer into that same database). In that case, just select the previous algorithm in the Dependencies parameter and they will be executed in the correct order.
Sobald allen Parametern gültige Werte zugewiesen wurden, klicken Sie auf OK und der Algorithmus wird der Oberfläche hinzugefügt. Er wird mit den Elementen auf der Oberfläche (Algorithmen oder Eingaben) verknüpft, die Objekte liefern, die als Eingaben für den Algorithmus verwendet werden.
Elements can be dragged to a different position on the canvas. This is useful to make the structure of the model more clear and intuitive. You can also resize elements. This is particularly useful if the description of the input or algorithm is long.
Links between elements are updated automatically and you can see a plus button at the top and at the bottom of each algorithm. Clicking the button will list all the inputs and outputs of the algorithm so you can have a quick overview.
You can zoom in and out by using the mouse wheel.

Abb. 22.24 Ein komplettes Modell¶
You can run your algorithm any time by clicking on the button.
In order to use the algorithm from the toolbox, it has to be saved
and the modeler dialog closed, to allow the toolbox to refresh its
contents.
22.5.3. Interacting with the canvas and elements¶
You can use the ,
,
and
buttons
to zoom the modeler canvas. The behavior of the buttons is basically the same
of the main QGIS toolbar.
The Undo History
panel together with the and
buttons are
extremely useful to quickly rollback to a previous situation. The
Undo History
panel lists everything you have done when creating the workflow.
You can move or resize many elements at the same time by first selecting them, dragging the mouse.
If you want to snap the elements while moving them in the canvas you can choose
.The
menu contains some very useful options to interact with your model elements:Snap Selected Components to Grid
: snap and align the elements into a gridDelete Selected Components: delete all the selected elements from the model
Add Group Box
: add a draggable box to the canvas. This feature is very useful in big models to group elements in the modeler canvas and to keep the workflow clean. For example we might group together all the inputs of the example:Abb. 22.25 Model Group Box¶
You can change the name and the color of the boxes. Group boxes are very useful when used together with
. This allows you to zoom to a specific part of the model.You might want to change the order of the inputs and how they are listed in the
main model dialog. At the bottom of the Input
panel you will find the
Reorder Model Inputs...
button and by clicking on it a new dialog pops up
allowing you to change the order of the inputs:

Abb. 22.26 Reorder Model Inputs¶
22.5.4. Speichern und laden von Modellen¶
Use the Save model button to save the current model and the
Open Model button to open a previously saved model.
Models are saved with the
.model3
extension.
If the model has already been saved from the modeler window,
you will not be prompted for a filename.
Since there is already a file associated with the model, that file
will be used for subsequent saves.
Bevor Sie ein Modell speichern, müssen Sie in den Textfeldern im oberen Teil des Fensters einen Namen und eine Gruppe für das Modell eingeben.
Modelle, die im Ordner models
gespeichert sind (der Standardordner, wenn Sie zur Eingabe eines Dateinamens zum Speichern des Modells aufgefordert werden), erscheinen in der Toolbox in der entsprechenden Rubrik. Wenn die Toolbox aufgerufen wird, durchsucht sie den Ordner models
nach Dateien mit der Erweiterung .model3
und lädt die darin enthaltenen Modelle. Da ein Modell selbst ein Algorithmus ist, kann es wie jeder andere Algorithmus zur Toolbox hinzugefügt werden.
Modelle können auch innerhalb der Projektdatei mit der Schaltfläche Modell im Projekt speichern gespeichert werden. Modelle, die mit dieser Methode gespeichert werden, werden nicht als :file:``.model3` Dateien auf die Platte geschrieben, sondern in die Projektdatei eingebettet.
Projektmodelle sind im Menü Projektmodelle der Toolbox verfügbar.
Die Verarbeitungsmodellierung kann im Verarbeitungskonfigurationsdialog in der Models Gruppe eingestellt werden.
Modelle, die aus dem Ordner models
geladen wurden, erscheinen nicht nur in der Toolbox, sondern auch in der Algorithmenliste im Reiter Algorithms des Modellierfensters. Das bedeutet, dass Sie ein Modell als Teil eines größeren Modells einbinden können, genau wie andere Algorithmen.
Models will show up in the Browser panel and can be run from there.
22.5.4.1. Exportieren eines Modells als Bild, PDF oder SVG¶
A model can also be exported as an image, SVG or PDF (for illustration
purposes) by clicking Export as image,
Export as PDF or
Export as SVG.
22.5.5. Ein Modell editieren¶
Sie können das Modell, das Sie gerade erstellen, bearbeiten und dabei den Workflow und die Beziehungen zwischen den Algorithmen und Eingaben, die das Modell definieren, ändern.
Wenn Sie mit der rechten Maustaste auf einen Algorithmus in der Leinwand klicken, sehen Sie ein Kontextmenü wie das folgende:

Abb. 22.27 Rechtsklick auf den Modeler¶
Wird die Remove Option gewählt, bewirkt dies, dass der ausgewählte Algorithmus entfernt wird. Ein Algorithmus kann nur entfernt werden wenn keine weiteren Algorithmen von ihm abhängen. Das heißt, wenn keine Ausgabe des Algorithmus in einem anderen als Eingabe verwendet wird. Wenn Sie versuchen einen Algorithmus, von dem andere abhängen, zu entfernen, wird eine Warnmeldung wie die, die Sie unten sehen können, gezeigt:

Abb. 22.28 Kann Algorithmus nicht entfernen¶
Selecting the Edit… option will show the parameter dialog of the algorithm, so you can change the inputs and parameter values. Not all input elements available in the model will appear as available inputs. Layers or values generated at a more advanced step in the workflow defined by the model will not be available if they cause circular dependencies.
Wählen Sie die neuen Werte aus und klicken Sie wie gewohnt auf die Schaltfläche OK. Die Verbindungen zwischen den Modellelementen ändern sich in der Modellierungsarbeitsfläche entsprechend.
The Add comment… allows you to add a comment to the algorithm to better describe the behavior.
A model can be run partially by deactivating some of its algorithms. To do it, select the Deactivate option in the context menu that appears when right-clicking on an algorithm element. The selected algorithm, and all the ones in the model that depend on it will be displayed in grey and will not be executed as part of the model.

Abb. 22.29 Modell mit deaktivierten Algorithmen¶
Wenn Sie mit der rechten Maustaste auf einen Algorithmus klicken, der nicht aktiv ist, sehen Sie die Menüoption :guilabel: Aktivieren, mit der Sie den Algorithmus reaktivieren können.
22.5.6. Editieren der Modell-Hilfe Datei und der Metainformationen¶
You can document your models from the modeler itself.
Click on the Edit model help button, and a
dialog like the one shown next will appear.

Abb. 22.30 Hilfe bearbeiten¶
Auf der rechten Seite finden Sie eine einfache HTML-Seite, die anhand der Eingabeparameter und Ausgaben des Algorithmus erstellt wurde, zusammen mit einigen zusätzlichen Einträgen wie eine allgemeine Beschreibung des Modells und seines Autors. Wenn Sie den Hilfeeditor das erste Mal öffnen, sind alle diese Beschreibungen leer, Sie können Sie aber mit Hilfe der Elemente auf der linken Seite des Dialogs bearbeiten. Wählen Sie ein Element im oberen Teil aus und schreiben Sie seine Beschreibung in das Textfeld unten.
Modell-Hilfe wird als Teil des Modells selbst gespeichert.
22.5.7. Exportieren eines Modells als Python Skript¶
As we will see in a later chapter, Processing algorithms can be called from the QGIS Python console, and new Processing algorithms can be created using Python. A quick way to create such a Python script is to create a model and then export it as a Python file.
To do so, click on the Export as Script Algorithm…
in the modeler canvas or right click on the name of the model in the Processing
Toolbox and choose
Export Model as Python Algorithm….
22.5.8. Zu den verfügbaren Algorithmen¶
Möglicherweise stellen Sie fest, dass einige Algorithmen, die über die Toolbox ausgeführt werden können, beim Entwurf eines Modells nicht in der Liste der verfügbaren Algorithmen erscheinen. Um in ein Modell aufgenommen zu werden, muss ein Algorithmus die richtige Semantik haben. Wenn ein Algorithmus nicht über eine so gut definierte Semantik verfügt (z. B. wenn die Anzahl der Ausgabelayer nicht im Voraus bekannt ist), kann er nicht in einem Modell verwendet werden, und er erscheint nicht in der Liste der Algorithmen, die Sie im Modellierungsdialog finden.