O modelador gráfico permite a criação de modelos complexos usando uma interface simples e de fácil utilização. Quando se trabalha com SIGs, a maioria das operações de análise não são isoladas, mas constituem parte de uma cadeia de operações. Usando o modelador gráfico, uma cadeia de processos pode ser acondicionada em um único processo, por isso é mais fácil e mais conveniente para a execução de um processo único. Não importa quantos passos e algoritmos diferentes sejam necessários, o modelo é executado como um algoritmo único, poupando tempo e esforço, especialmente para modelos maiores, que envolem muitos processos.
The modeler can be opened from the processing menu.
O modelador tem uma área de trabalho, onde a estrutura do modelo e o fluxo de trabalho representados são mostrados.
Figure Processing 16:
A criação de um modelo envolve duas etapas:
Definição do fluxo de trabalho. Usando os dados de entrada do modelo, o fluxo de trabalho é definido adicionando algoritmos e selecionando como estes algoritmos devem usar essas entradas ou saídas geradas por outros algoritmos ou que foram inseridas como parâmetro no início do modelo
The first step to create a model is to define the inputs it needs. The following elements are found in the Inputs tab on the left side of the modeler window:
Raster layer (Camada raster)
Vector layer (Camada vetorial)
String (Campo de texto)
Table field (Campo de tabela)
Table (Tabela)
Double-clicking on any of them, a dialog is shown to define its characteristics. Depending on the parameter itself, the dialog will contain just one basic element (the description, which is what the user will see when executing the model) or more of them. For instance, when adding a numerical value, as it can be seen in the next figure, apart from the description of the parameter you have to set a default value and a range of valid values.
Figure Processing 17:
Para cada entrada adicionada, um novo elemento é adicionado à tela do modelador.
Figure Processing 18:
Once the inputs have been defined, it is time to define the algorithms to apply on them. Algorithms can be found in the Algorithms tab, grouped much in the same way as they are in the toolbox.
Figure Processing 19:
The appearance of the toolbox has two modes here as well: simplified and advanced. However, there is no element to switch between views in the modeler, and you have to do it in the toolbox. The mode that is selected in the toolbox is the one that will be used for the list of algorithms in the modeler.
To add an algorithm to a model, double-click on its name. 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 one shown next correspond to the SAGA ‘Convergence index’ algorithm, the same one we saw in the section dedicated to the toolbox.
Figure Processing 20:
As you can see, some differences exist. Instead of the file output box that was used to set the filepath for output layers and tables, a simple text box is. If the layer generated by the algorithm is just a temporary result that will be used as the input of another algorithm and should not be kept as a final result, just do not edit that text box. Typing anything on it means that the result is a final one, and the text that you supply will be the description for the output, which will be the one the user will see when executing the model.
Selecting the value of each parameter is also a bit different, since there are important differences between the context of the modeler and the toolbox one. Let’s see how to introduce the values for each type of parameter.
Campo de texto. Como no caso de valores numéricos, textos podem ser digitados diretamente nos campos de textos, além de ser possível selecionar uma sequência de entradas.
In all cases, you will find an additional parameter named Parent algorithms 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, which will force it to be executed before it.
When you use the output of a previous algorithm as the input of your algorithm, that implicitly sets the former 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, and algorithm that executes an SQL sentence on a PostGIS database and another one which imports a layer into that same database) In that case, just select it in the Parent algorithms parameter and they will be executed in the correct order.
Once all the parameter have been assigned valid values, click on [OK] and the algorithm will be added to the canvas. It will be linked to all the other elements in the canvas, whether algorithms or inputs, which provide objects that are used as inputs for that algorithm.
Figure Processing 21:
Os elementos podem ser arrastados para uma posição diferente dentro da tela do modelador, para mudar a forma como a estrutura do módulo é apresentado e torná-la mais clara e intuitiva. As ligações entre os elementos são atualizadas automaticamente.
You can run your algorithm anytime clicking on the [Run] button. However, in order to use it from the toolbox, it has to be saved and the modeler dialog closed, to allow the toolbox to refresh its contents.
Use the [Save] button to save the current model and the [Open] one to open any model previously saved. Model are saved with the .model extension. If the model has been previously saved from the modeler window, you will not be prompted for a filename, since there is already a file associated with that model, and it will be used.
Antes de salvar um modelo, é necessário digitar um nome e um grupo para ele, usando as caixas de texto na parte superior da janela.
Models saved on 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 .model 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.
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 as you add any other algorithm.
In some cases, a model might not be loaded because not all the algorithms included in its workflow are available. If you have used a given algorithm as part of your model, it should be available (that is, it should appear on the toolbox) in order to load that model. Deactivating an algorithm provider in the processing configuration window renders all the algorithms in that provider unusable by the modeler, which might cause problems when loading models. Keep that in mind when you have trouble loading or executing models.
É possível editar um modelo já existente, redefinindo o fluxo seu de trabalho e as relações entre os algoritmos e os elementos que constituem o modelo.
Se você clicar em um algoritmo na tela que apresenta o modelo, você verá um menu de contexto, como mostrada a seguir:
Figure Processing 22:
Selecting the Remove option will cause the selected algorithm to be removed. An algorithm can be removed only if there are no other algorithms depending on it. That is, if no output from the algorithm is used in a different one as input. If you try to remove an algorithm that has others depending on it, a warning message like the one you can see below will be shown:
Figure Processing 23:
Selecting the Edit option or simply double-clicking on the algorithm icon will show the parameters dialog of the algorithm, so you can change the inputs and parameter values. Not all input elements available in the model will appear in this case 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 then click on the [OK] button as usual. The connections between the model elements will change accordingly in the modeler canvas.
Algoritmos podem ser desativados no modelador, para que eles não sejam executados durante a execução do modelo. Isso pode ser útil para testar apenas uma determinada parte do modelo, ou quando você não precisa de todas as saídas que são geradas.
To deactivate an algorithm, right-click on its icon in the model canvas and select the Deactivate option. You will see that the algorithm is represented now with a red label under its name indicating that is not active.
Figure Processing 24:
Todos os algoritmos dependentes (diretamente ou indiretamente) do algoritmo desativado, também aparecem como inativo, já que não podem ser executados.
To activate an algorithm, just right–click on its icon and select the Activate option.
You can document your models from the modeler itself. Just click on the [Edit model help] button and a dialog like the one shown next will appear.
Figure Processing 25:
On the right-hand side you will see a simple HTML page, created using the description of the input parameters and outputs of the algorithm, along with some additional items like a general description of the model or its author. The first time you open the help editor all those descriptions are empty, but you can edit them using the elements on the left-hand side of the dialog. Select an element on the upper part and the write its description in the text box below.
A Ajuda do modelo é salva em um arquivo na mesma pasta do arquivo do próprio modelo. Você não tem que se preocupar em salvá-lo, uma vez que o salvamento é feito automaticamente.
Você pode notar que alguns algoritmos que podem ser executados a partir da caixa de ferramentas não aparecem na lista dos algoritmos disponíveis quando está projetando um modelo. Para ser incluído em um modelo, um algoritmo deve ter uma semântica correta, de modo a ser adequadamente ligado a outro, no fluxo de trabalho. Se um algoritmo não tem tal semântica bem definida (por exemplo, se o número de camadas de saída não se pode ser definido antecipadamente), então não é possível utilizá-lo dentro de um modelo e, assim, não aparecem na lista que você pode encontrar na janela do modelador.
Additionally, you will see some algorithms in the modeler that are not found in the toolbox. This algorithms are meant to be used exclusively as part of a model, and they are of no interest in a different context. The ‘Calculator’ algorithm is an example of that. It is just a simple arithmetic calculator that you can use to modify numerical values (entered by the user or generated by some other algorithm). This tools is really useful within a model, but outside of that context, it doesn’t make too much sense.
Given a model, it is possible to automatically create Python code that performs the same task as the model itself. This code is used to create a console script (we will explain them later in this manual) and you can modify that script to incorporate actions and methods not available in the graphical modeler, such as loops or conditional sentences.
This feature is also a very practical way of learning how to use processign algorithms from the console and how to create new algorithms using Python code, so you can use it as a learning tool when you start creating your own scripts.
Save your model in the models folder and go to the toolbox, where it should appear now, ready to be run. Right click on the model name and select Save as Python script in the context menu that will pop-up. A dialog will prompt you to introduce the file where you want to save the script.