17.8. Rularea unui algoritm extern

Notă

În această lecție vom vedea cum să folosim algoritmi care depind de o terță aplicație, în speță SAGA, care este unul dintre principalii furnizori de algoritmi.

All the algorithms that we have run so far are part of processing framework. That is, they are native algorithms implemented in the plugin and run by QGIS just like the plugin itself is run. However, one of the greatest features of the processing framework is that it can use algorithms from external applications and extend the possibilities of those applications. Such algorithms are wrapped and included in the toolbox, so you can easily use them from QGIS, and use QGIS data to run them.

Pentru a rula, unii dintre algoritmii pe care îi vedeți în vizualizarea simplificată necesită, în prealabil, instalarea unor aplicații terțe în sistemul dumneavoastră. Un furnizor de algoritm de interes special este SAGA (Sistem de Analize Geospațiale Automate). Pentru a apela în mod corect SAGA, QGIS trebuie să fie configurat în mod corespunzător. Acest lucru nu este dificil, dacă înțelegem principiul de funcționare. Fiecare aplicație externă are propria sa configurație, iar mai târziu, în același manual vom vorbi despre altele, însă acum vom discuta despre SAGA.

În cazul în care vă aflați pe Windows, cel mai bun mod de a lucra cu algoritmii externi este de a instala QGIS cu ajutorul programului de instalare. Acesta va avea grijă de instalarea dependențelor necesare, inclusiv SAGA, astfel că, dacă l-ați folosit, nu mai trebuie să întreprindeți altceva. Puteți deschide dialogul setărilor, apoi să mergeți la grupul Furnizorilor/SAGA.

../../../_images/saga_config.png

Calea către SAGA trebuie să fie deja configurată și să indice folderul în care este instalat SAGA.

Dacă ați instalat QGIS fără să folosiți programul autonom de instalare, atunci trebuie să introduceți calea către SAGA (care trebuie să fie deja instalată). Versiunea necesară este SAGA 2.1 [aceasta se schimbă în funcție de versiunile de SAGA].

In case you are using Linux, you do not have to set the path to your SAGA installation in the processing configuration. Instead, you must install SAGA and make sure that the SAGA folder is in PATH, so it can be called from the console (just open a console and type saga_cmd to check it). Under Linux, the target version for SAGA is also 2.1, but in some installations (such as the OSGeo Live DVD) you might have just 2.0.8 available. There are some 2.1 packages available, but they are not commonly installed and might have some issues, so if you prefer to use the more common and stable 2.0.8, you can do it by enabling 2.0.8 compatibility in the configuration dialog, under the SAGA group.

../../../_images/enable208.png

O dată ce SAGA este instalat, puteți lansa un algoritm SAGA printr-un dublu clic pe numele său, similar celorlalți algoritmi. Din moment ce folosim interfața simplificată, nu știm care dintre algoritmi se bazează pe SAGA sau pe o altă aplicație externă, dar dacă se întâmplă să rulați unul pentru care aplicația corespunzătoare nu este instalată, vi se va indica acest lucru.

../../../_images/missing_saga.png

În cazul nostru, presupunând că aplicația SAGA este instalată și configurată corect, nu ar trebui să vedeți această fereastră ci, în schimb, veți obține parametrii dialogului.

Să încercăm cu un algoritm bazat pe SAGA, cel denumit Split shapes layer randomly.

../../../_images/split.png

Folosind ca intrare stratul de puncte din proiectul corespunzător acestei lecții, împreună cu valorile implicite ale parametrilor, veți obține ceva de genul următor (divizarea este aleatorie, de aceea rezultatul dvs. poate fi diferit).

../../../_images/split_layer.png

The input layer has been split in two layers, each one with the same number of points. This result has been computed by SAGA, and later taken by QGIS and added to the QGIS project.

If all goes fine, you will not notice any difference between this SAGA–based algorithm and one of the others that we have previously run. However, SAGA might, for some reason, not be able to produce a result and not generate the file that QGIS is expecting. In that case, there will be problems adding the result to the QGIS project, and an error message like this will be shown.

../../../_images/missing_result.png

This kind of problems might happen, even if SAGA (or any other application that we are calling from the processing framework) is correctly installed, and it is important to know how to deal with them. Let’s produce one of those error messages.

Deschideți algoritmul Creare graticule, și folosiți-l cu următoarele valori.

../../../_images/create_graticule.png

We are using width and height values that is larger than the specified extent, so SAGA cannot produce any output. In other words, the parameter values are wrong, but they are not checked until SAGA gets them and tries to create the graticule. Since it cannot create it, it will not produce the expected layer, and you will see the error message shown above.

Notă

În SAGA >= 2.2.3, comanda va ajusta în mod automat datele de intrare greșite, așa că nu veți obține o eroare. Pentru a provoca o eroare, utilizați valori negative la divizare.

Understanding this kind of problems will help you solve them and find an explanation to what is happening. As you can see in the error message, a test is performed to check that the connection with SAGA is working correctly, indicating you that there might be a problem in how the algorithm was executed. This applies not only to SAGA, but also to other external applications as well.

In the next lesson we will introduce the processing log, where information about commands run by geoalgorithms is kept, and you will see how to get more detail when issues like this appear.