26.5. O modelador gráfico

The graphical modeler allows you to create complex models using a simple and easy-to-use interface. When working with a GIS, most analysis operations are not isolated, rather part of a chain of operations. Using the graphical modeler, that chain of operations can be wrapped into a single process, making it convenient to execute later with a different set of inputs. No matter how many steps and different algorithms it involves, a model is executed as a single algorithm, saving time and effort.

The graphical modeler can be opened from the Processing menu (Processing ► Graphical Modeler).

26.5.1. A interface gráfica de modelagem


Fig. 26.16 Modelador

In its main part, the modeler has a working canvas where the structure of the model and the workflow it represents can be constructed.

At the top of the dialog, different menus and the Navigation toolbar give access to a variety of tools. Menu modelo



Barra de ferramentas de navegação


sucesso Validate Model

Checks whether the algorithms and inputs used in the model exist. Convenient before releasing a model.

play Run Model…



Executa o modelo

guilabel:Reordenar entradas do modelo…

Sets the order in which inputs are presented to the user in the algorithm dialog.

fileOpen Open Model…



Opens a .model3 file for edit or execution

fileSave Salvar Modelo



Saves the model to disk as a .model3 file

fileSaveAs Salvar Modelo como…



Saves the model to disk as a new .model3 file

fileSave Save Model in project


Incorpora o arquivo de modelo no arquivo de projeto, tornando-o disponível ao compartilhar o arquivo de projeto.

helpContents Edit Model Help…


Uma interface para documentar o modelo, os algoritmos, os parâmetros e as saídas, bem como o autor e versão

Exportar ►

saveMapAsImage ► Exportar como Imagem…


Salva o design gráfico do modelo em um formato de arquivo de imagem (para fins de ilustração)

saveAsPDF► Exportar como PDF…

Saves the model’s graphical design to a PDF file format (for illustration purpose)

salvarComoSVG► Exportar como SVG…

Saves the model’s graphical design to an SVG file format (for illustration purpose)

fileSave► Export as Script Algorithm…


Gera um arquivo de script python incluindo as instruções do modelo Editar menu



Barra de ferramentas de navegação


selectAll Selecionar tudo


Seleciona todos os componentes do modelo no design

Snap selected components to Grid

snaps and aligns the elements into a grid

redo Refazer



Rollback the latest canceled action. See also the Undo/Redo panel.

undo Desfazer



Cancel the previous change. See also the Undo/Redo panel.

editCut Cortar


Corta uma seleção de componentes do modelo.

editCopy Copiar


Copia uma seleção de componentes do modelo.

editPaste Colar


Cola uma seleção recortada ou copiada de componentes de um modelo para outro ou dentro do mesmo modelo. Os componentes selecionados mantêm suas propriedades e comentários originais.

deleteSelected Delete selected components


Remove um componente do modelo.

Add Group Box

Adds a box at the background of related components in order to visually group them. Particularly useful in big models to keep the workflow clean. ver menu



Barra de ferramentas de navegação


Zoom To ►

Zooms to the selected group box extent

zoomIn Zoom In



zoomOut Reduzir Zoom



zoomActual Zoom to 100%



zoomFullExtent Zoom Full



Displays all the components in the designer current canvas

checkbox Mostrar comentários

Displays comments associated to every algorithm or input in the graphical designer

unchecked Enable Snapping

unchecked Toggle Panel Visibility


Switches ON or OFF the panels in the designer Painéis

The left part of the window is a section with five panels that can be used to add new elements to the model:

  1. Model Properties: specify the name (required) of the model and the group in which it will be displayed in the Processing Toolbox

  2. Inputs: all the input parameters that could shape your model

  3. Algorithms: the available Processing algorithms

  4. Variables: Models can contain dedicated variables that are unique and only available to them. These variables can be accessed by any expression used within the model. They are useful to control algorithms within a model and control multiple aspects of the model by changing a single variable. The variables can be viewed and modified in the Variables panel.

  5. Undo History: this panel will register everything that happens in the modeler, making it easy to cancel things you did wrong. Sobre os algoritmos disponíveis

Some algorithms that can be executed from the toolbox do not appear in the list of available algorithms when you are designing a model. To be included in a model, an algorithm must have the correct semantic. If an algorithm does not have such a well-defined semantic (for instance, if the number of output layers cannot be known in advance), then it is not possible to use it within a model, and it will not appear in the list of algorithms that you can find in the modeler dialog. On the other hand some algorithms are specific to the modeler. Those algorithms are located within the group ‘Modeler Tools’.

26.5.2. Criando um modelo

A criação de um modelo envolve duas etapas básicas:

  1. 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.

  2. Definition of the workflow. Using the input data of the model, the workflow is defined by adding algorithms and selecting how they use the defined inputs or the outputs generated by other algorithms in the model. Definição das entradas

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:

Tabela 26.1 Lista de tipos de parâmetros para construção de modelos

Annotation Layer

Authentication Configuration



Connection Name

Coordinate Operation


Database Schema

Database Table




DXF Layers




Field Aggregates

Fields Mapper



Map Layer

Map Theme


Mesh Dataset Groups

Mesh Dataset Time

Mesh Layer

Multiple Input



Point Cloud Layer

Print Layout

Print Layout Item


Raster Band

Raster Layer



TIN Creation Layers

Vector Features

Vector Field

Vector Layer

Vector Tile Writer Layers


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.


Fig. 26.17 Definição dos Parâmetros do Modelo

You can define your input as mandatory for your model by checking the checkbox Mandatory option and by checking the unchecked 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.

For each added input, a new element is added to the modeler canvas.


Fig. 26.18 Parâmetros do modelo

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.

When using a model within another model, the inputs and outputs necessary will be displayed in the canvas. Definição do fluxo de trabalho

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.


Fig. 26.19 Model Inputs

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.


Fig. 26.20 Model Algorithm parameters

As you can see, there are however some differences. Each parameter has a drop-down menu next to it allowing to control how it will be served during the workflow:

  • campoInteiro Value: allows you to assign a static value to the parameter. Depending on the parameter type, the widget will let you enter a number (5.0), a string (mytext), select layer(s) loaded in the QGIS project or from a folder, pick items from a list, …

  • expression Pre-calculated Value: opens the Expression Builder dialog and lets you define an 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 Builder. The expression is evaluated once before the child algorithm is executed and used during the execution of that algorithm.

  • processingModel Model Input: allows to use an input added to the model as a parameter. Once clicked, this option will list all the suitable inputs for the parameter.

  • processingAlgorithm Algorithm Output: allows to use the output of another algorithm as an input of the current algorithm. As of model inputs, this option will list all the suitable inputs for the parameter.

  • The output parameter also has the above options in its drop-down menu:

    • add static outputs for child algorithms, e.g. always saving a child algorithm’s output to a predefined geopackage or postgres layer

    • use an expression based output values for child algorithms, e.g. generating an automatic file name based on today’s date and saving outputs to that file

    • use a model input, e.g. the File/Folder model input to specify an output file or folder

    • use another algorithm output, e.g. the output of the Create directory algorithm (from Modeler tools)

    • an addditional saída do modelo Model Output option 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:


    Fig. 26.21 Parâmetros de entrada e saída de algoritmo

You will also 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.

Once all the parameters have been assigned valid values, click on OK and the algorithm will be added to the canvas. It will be linked to the elements in the canvas (algorithms or inputs) that provide objects that are used as inputs for the algorithm.

Elements can be dragged to a different position on the canvas using the selecionar Select/Move Item tool. This is useful to make the structure of the model clearer and more intuitive. You can also resize the elements, grasping their border. This is particularly useful if the description of the input or algorithm is long. With View ► Enable snapping option checked, items resizing or displacement can be bound to a virtual grid, for a more visually structured algorithm design.

Os links entre os elementos são atualizados automaticamente e você pode ver um botão + na parte superior e inferior de cada algoritmo. Clicar no botão listará todas as entradas e saídas do algoritmo para que você possa ter uma visão geral rápida.


Fig. 26.22 Um modelo completo

With the Edit ► Add Group Box tool, you can add a draggable box to the canvas. This feature is very useful in big models to group related elements in the modeler canvas and to keep the workflow clean. For example we might group together all the inputs of the example:


Fig. 26.23 Model Group Box

You can change the name and the color of the boxes. Group boxes are very useful when used together with View ► Zoom To ► tool, allowing you to zoom to a specific part of the model. You can also zoom in and out by using the mouse wheel.

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:


Fig. 26.24 Reorder Model Inputs

Comments can also be added to inputs or algorithms present in the modeler. This can be done by going in the Comment tab of the item or with a right-click. In the same tab a color can be set manual for individual model comments. Comments are visible only in the modeler canvas and not in the final algorithm dialog; they can be hidden by deactivating View ► Show Comments.

You can run your algorithm any time by clicking on the iniciar Run model button. When using the editor to execute a model, any non-default values will be saved in the inputs. This means that executing the model at a later time from the editor will have the dialog prefilled with those values on any subsequent run.

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. Documentando seu modelo

You need to document your model, and this can be done from the modeler itself. Click on the editar conteúdo de ajudaEdit model help button, and a dialog like the one shown next will appear.


Fig. 26.25 Editing Help

No lado direito irá ver uma página simples HTML, criada usando a descrição dos parâmetros de entrada e de saída do algoritmo, juntamente com itens adicionais como uma descrição geral do modelo ou o seu autor. A primeira vez que abre o editor da ajuda, todas as ajudas estão vazias, mas pode editá-los usando os elementos do lado esquerdo do diálogo. Selecione um elemento na parte superior e escreva a descrição na caixa de texto em baixo.

Model help is saved as part of the model itself.

26.5.3. Salvando e carregando os modelos Salvando modelos

Use the fileSaveSave model button to save the current model and the fileOpenOpen 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.

Antes de salvar um modelo, você deve inserir um nome e um grupo para ele nas caixas de texto na parte superior da janela.

Models saved in the models folder (the default folder when you are prompted for a filename to save the model) will appear in the toolbox in the corresponding branch. When the toolbox is invoked, it searches the models folder for files with the .model3 extension and loads the models they contain. Since a model is itself an algorithm, it can be added to the toolbox just like any other algorithm.

Models can also be saved within the project file using the addToProjectSave model in project button. Models saved using this method won’t be written as .model3 files on the disk but will be embedded in the project file.

Project models are available in the qgsProjectFileProject models menu of the toolbox and in the Project ► Models menu item.

The models folder can be set from the Processing configuration dialog, under the Modeler group.

Models loaded from the models folder appear not only in the toolbox, but also in the algorithms tree in the Algorithms tab of the modeler window. That means that you can incorporate a model as a part of a bigger model, just like other algorithms.

Models will show up in the Browser panel and can be run from there. Exportando um modelo como um script Python

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 salvarComoPythonExport as Script Algorithm… in the modeler canvas or right click on the name of the model in the Processing Toolbox and choose salvarComoPythonExport Model as Python Algorithm…. Exportando um modelo como imagem, PDF ou SVG

A model can also be exported as an image, SVG or PDF (for illustration purposes) by clicking saveMapAsImageExport as image, saveAsPDFExport as PDF or salvarComoSVGExport as SVG.

26.5.4. Editando um modelo

Você pode editar o modelo que está criando atualmente, redefinindo o fluxo de trabalho e os relacionamentos entre os algoritmos e as entradas que definem o modelo.

If you right-click on an algorithm in the canvas, you will see a context menu like the one shown next:


Fig. 26.26 Modeler Right Click

Selecionando a opção Remover irá fazer com que o algoritmo seja removido. Um algoritmo só pode ser removido apenas se existir outros algoritmos dependentes dele. Isto é, se não estiver sendo usado num arquivo de saída de um algoritmo usado como arquivo de entrada diferente. Se tentar remover um algoritmo que tenha outros que dependam dele, uma mensagem de aviso igual à que vê aqui em baixo:


Fig. 26.27 Não é Possível Excluir o Algoritmo

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.

Select the new values and click on the OK button as usual. The connections between the model elements will change in the modeler canvas accordingly.

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.


Fig. 26.28 Model With Deactivated Algorithms

When right-clicking on an algorithm that is not active, you will see a Activate menu option that you can use to reactivate it.