.

Configurar aplicaciones externas

The processing framework can be extended using additional applications. Currently, SAGA, GRASS, OTB (Orfeo Toolbox) and R are supported, along with some other command-line applications that provide spatial data analysis functionalities. Algorithms relying on an external application are managed by their own algorithm provider.

Esta sección le mostrará cómo configurar el entorno de procesamiento para incluir estas aplicaciones adicionales, y le explicará algunas de las características particulares de los algoritmos basados en ellos. Una vez que haya configurado correctamente el sistema, usted será capaz de ejecutar algoritmos externos de cualquier componente, como la caja de herramientas o el modelador gráfico, tal como lo hace con cualquier otro geoalgoritmo.

By default, all algorithms that rely on an external appplication not shipped with QGIS are not enabled. You can enable them in the configuration dialog. Make sure that the corresponding application is already installed in your system. Enabling an algorithm provider without installing the application it needs will cause the algorithms to appear in the toolbox, but an error will be thrown when you try to execute them.

This is because the algorithm descriptions (needed to create the parameters dialog and provide the information needed about the algorithm) are not included with each application, but with QGIS instead. That is, they are part of QGIS, so you have them in your installation even if you have not installed any other software. Running the algorithm, however, needs the application binaries to be installed in your system.

Aclaración para los usuarios de Windows

If you are not an advanced user and you are running QGIS on Windows, you might not be interested in reading the rest of this chapter. Make sure you install QGIS in your system using the standalone installer. That will automatically install SAGA, GRASS and OTB in your system and configure them so they can be run from QGIS. All the algorithms in the simplified view of the toolbox will be ready to be run without needing any further configuration. If installing through OSGeo4W application, make sure you select for insttallation SAGA and OTB as well.

Si quiere saber más sobre cómo funcionan estos proveedores, o si quiere utilizar algún algoritmo que no se encuentre en la Caja de Herramientas simplificada (como los scripts de R), siga leyendo.

Aclaración respecto a los formatos de archivos

When using an external software, opening a file in QGIS does not mean that it can be opened and processed as well in that other software. In most cases, other software can read what you have opened in QGIS, but in some cases, that might not be true. When using databases or uncommon file formats, whether for raster or vector layers, problems might arise. If that happens, try to use well-known file formats that you are sure are understood by both programs, and check the console output (in the history and log dialog) to know more about what is going wrong.

Utilizar capas raster de GRASS es, por ejemplo, uno de los casos en los que pueden existir problemas y no completarse el trabajo si se invoca un algoritmo externo que use dicha capa como entrada. Por este motivo, estas capas no aparecerán como disponibles para los algoritmos.

You should, however, find no problems at all with vector layers, since QGIS automatically converts from the original file format to one accepted by the external application before passing the layer to it. This adds extra processing time, which might be significant if the layer has a large size, so do not be surprised if it takes more time to process a layer from a DB connection than it does to process one of a similar size stored in a shapefile.

Providers not using external applications can process any layer that you can open in QGIS, since they open it for analysis through QGIS.

Regarding output formats, all formats supported by QGIS as output can be used, both for raster and vector layers. Some providers do not support certain formats, but all can export to common raster layer formats that can later be transformed by QGIS automatically. As in the case of input layers, if this conversion is needed, that might increase the processing time.

If the extension of the filename specified when calling an algorithm does not match the extension of any of the formats supported by QGIS, then a suffix will be added to set a default format. In the case of raster layers, the .tif extension is used, while .shp is used for vector layers.

Nota referente a las seleccion de capas vectoriales

External applications may also be made aware of the selections that exist in vector layers within QGIS. However, that requires rewriting all input vector layers, just as if they were originally in a format not supported by the external application. Only when no selection exists, or the Use only selected features option is not enabled in the processing general configuration, can a layer be directly passed to an external application.

En otros casos sólo es necesario exportar un conjunto de características seleccionadas, lo que hará que los tiempos de ejecución sean mayores.

SAGA

SAGA algorithms can be run from QGIS if you have SAGA installed in your system and you configure the processing framework properly so it can find SAGA executables. In particular, the SAGA command-line executable is needed to run SAGA algorithms.

If you are running Windows, both the stand-alone installer and the OSGeo4W installer include SAGA along with QGIS, and the path is automatically configured, so there is no need to do anything else.

If you have installed SAGA yourself (remember, you need version 2.1), the path to the SAGA executable must be configured. To do this, open the configuration dialog. In the SAGA block, you will find a setting named SAGA Folder. Enter the path to the folder where SAGA is installed. Close the configuration dialog, and now you are ready to run SAGA algorithms from QGIS.

If you are running Linux, SAGA binaries are not included with SEXTANTE, so you have to download and install the software yourself. Please check the SAGA website for more information. SAGA 2.1 is needed.

In this case, there is no need to configure the path to the SAGA executable, and you will not see those folders. Instead, you must make sure that SAGA is properly installed and its folder is added to the PATH environment variable. Just open a console and type saga_cmd to check that the system can find where the SAGA binaries are located.

Sobre las limitaciones del sistema de cuadrícula de SAGA

Most SAGA algorithms that require several input raster layers require them to have the same grid system. That is, they must cover the same geographic area and have the same cell size, so their corresponding grids match. When calling SAGA algorithms from QGIS, you can use any layer, regardless of its cell size and extent. When multiple raster layers are used as input for a SAGA algorithm, QGIS resamples them to a common grid system and then passes them to SAGA (unless the SAGA algorithm can operate with layers from different grid systems).

La definición de este sistema de cuadrícula común es controlado por el usuario, y se encontrará varios parámetros en el grupo SAGA de la ventana de configuración para hacerlo. Hay dos formas de establecer el sistema de cuadrícula de destino.

  • Establecerlo manualmente. se define la extensión estableciendo los valores de los siguientes parámetros:

    • Resampling min X
    • Resampling max X
    • Resampling min Y
    • Resampling max Y
    • Resampling cellsize

    Notice that QGIS will resample input layers to that extent, even if they do not overlap with it.

  • Ajuste de forma automática a partir de capas de entrada. Para seleccionar esta opción, simplemente marque la opción Utilizar el sistema de cuadrícula mínima para remuestreo. Todos los demás ajustes se ignoran y la medida mínima que cubre todas las capas de entrada que se utilizarán. El tamaño de celda de la capa de destino es el máximo de todos los tamaños celulares de las capas de entrada.

Para los algoritmos que no utilizan múltiples capas raster, o para aquellos que no necesitan un único sistema de cuadrícula de entrada, no se realizará un remuestreo antes de invocar SAG y dichos parámetros no son utilizados.

Limitaciones para las capas multibanda

Unlike QGIS, SAGA has no support for multi-band layers. If you want to use a multiband layer (such as an RGB or multispectral image), you first have to split it into single-banded images. To do so, you can use the ‘SAGA/Grid - Tools/Split RGB image’ algorithm (which creates three images from an RGB image) or the ‘SAGA/Grid - Tools/Extract band’ algorithm (to extract a single band).

Limitaciones en el tamaño de celda

SAGA asume que las capas ráster tienen el mismo tamaño de celda en el eje X y Y. Si se está trabajando con una capa con diferentes valores para el tamaño de celda horizontal y vertical, es posible que obtenga resultados inesperados. En este caso, se añadirá una advertencia al registro de procesamiento, lo que indica que una capa de entrada podría no ser adecuada para ser procesada por SAGA.

Registro

When QGIS calls SAGA, it does so using its command-line interface, thus passing a set of commands to perform all the required operations. SAGA shows its progress by writing information to the console, which includes the percentage of processing already done, along with additional content. This output is filtered and used to update the progress bar while the algorithm is running.

Both the commands sent by QGIS and the additional information printed by SAGA can be logged along with other processing log messages, and you might find them useful to track in detail what is going on when QGIS runs a SAGA algorithm. You will find two settings, namely Log console output and Log execution commands, to activate that logging mechanism.

La mayoría del resto de proveedores que utilizan una aplicación externa y la invocan a través de la línea de comandos tienen opciones similares, de forma que las podrá encontrar también en otros lugares de la lista de ajustes de procesamiento.

R. Creating R scripts

R integration in QGIS is different from that of SAGA in that there is not a predefined set of algorithms you can run (except for a few examples). Instead, you should write your scripts and call R commands, much like you would do from R, and in a very similar manner to what we saw in the section dedicated to processing scripts. This section shows you the syntax to use to call those R commands from QGIS and how to use QGIS objects (layers, tables) in them.

The first thing you have to do, as we saw in the case of SAGA, is to tell QGIS where your R binaries are located. You can do this using the R folder entry in the processing configuration dialog. Once you have set that parameter, you can start creating and executing your own R scripts.

De nuevo, esto es diferente en Linux, dónde sólo hay que asegurarse de que el directorio de R está correctamente incluido en la variable de entorno PATH. Si R puede iniciarse simplemente escribiendo R en una consola, entonces la configuración es correcta.

To add a new algorithm that calls an R function (or a more complex R script that you have developed and you would like to have available from QGIS), you have to create a script file that tells the processing framework how to perform that operation and the corresponding R commands to do so.

Los archivos de script de R tienen la extensión .rsx, y crearlos es bastante sencillo si sólo tiene un conocimiento básico de la sintaxis y script de R. Deben ser almacenados en la carpeta de scripts de R. Se puede establecer esta carpeta en el grupo de ajustes R (disponible desde el diálogo de Configuración de procesamiento), al igual que se hace con la carpeta para scripts de procesamiento regular.

Let’s have a look at a very simple script file, which calls the R method spsample to create a random grid within the boundary of the polygons in a given polygon layer. This method belongs to the maptools package. Since almost all the algorithms that you might like to incorporate into QGIS will use or generate spatial data, knowledge of spatial packages like maptools and, especially, sp, is mandatory.

##polyg=vector
##numpoints=number 10
##output=output vector
##sp=group
pts=spsample(polyg,numpoints,type="random")
output=SpatialPointsDataFrame(pts, as.data.frame(pts))

The first lines, which start with a double Python comment sign (##), tell QGIS the inputs of the algorithm described in the file and the outputs that it will generate. They work with exactly the same syntax as the SEXTANTE scripts that we have already seen, so they will not be described here again.

When you declare an input parameter, QGIS uses that information for two things: creating the user interface to ask the user for the value of that parameter and creating a corresponding R variable that can later be used as input for R commands.

In the above example, we are declaring an input of type vector named polyg. When executing the algorithm, QGIS will open in R the layer selected by the user and store it in a variable also named polyg. So, the name of a parameter is also the name of the variable that we can use in R for accesing the value of that parameter (thus, you should avoid using reserved R words as parameter names).

Spatial elements such as vector and raster layers are read using the readOGR() and brick() commands (you do not have to worry about adding those commands to your description file – QGIS will do it), and they are stored as Spatial*DataFrame objects. Table fields are stored as strings containing the name of the selected field.

Las tablas se abren con el comando read.csv(). Sin una tabla introducida por el usuario no esta en formato CSV, será convertirá antes de importarlo en R.

Además, los ráster se pueden leer con el comando readGDAL()` en lugar de ``brick() utilizando el ##usereadgdal.

If you are an advanced user and do not want QGIS to create the object representing the layer, you can use the ##passfilename tag to indicate that you prefer a string with the filename instead. In this case, it is up to you to open the file before performing any operation on the data it contains.

Con la información anterior, se puede comprender la primera línea de nuestro primer script de ejemplo (la primera línea que no comienza con un comentario de Python).

pts=spsample(polyg,numpoints,type="random")

La variable polygon ya contiene un objeto SpatialPolygonsDataFrame, por lo que se puede utilizar para llamar al método spsample, al igual que numpoints, que indica el número de puntos a añadir a la rejilla de ejemplo creada.

Como hemos declarado una salida de tipo vectorial llamada salida, tenemos que crear una variable llamada salida y almacenar un objeto Spatial*DataFrame en ella (en este caso, un SpatialPointsDataFrame). Se puede utilizar cualquier nombre para sus variables intermedias. Sólo asegúrese de que la variable almacena su resultado final y que tiene el mismo nombre que utilizó al declararla, y que contiene un valor adecuado.

In this case, the result obtained from the spsample method has to be converted explicitly into a SpatialPointsDataFrame object, since it is itself an object of class ppp, which is not a suitable class to be returned to QGIS.

Si el algoritmo genera capas raster, la forma en que se guardan dependerá de si o no han utilizado la opción #dontuserasterpackage. En que lo ha usado, las capas se guardan utilizando el método writeGDAL (). Si no, se utilizará el método writeRaster() del paquete ráster.

Si ha utilizado la opción #passfilename, las salidas se generan utilizando el paquete raster (mediante writeRaster()), incluso cuando no se utiliza para las entradas.

Si el algoritmo no genera ninguna capa, sino más bien en su lugar regresa un texto en la consola, tiene que indicar lo que desea que la consola mostrará una vez finalizada la ejecución. Para ello, basta con iniciar la línea de comandos que producen los resultados que desea imprimir con el signo > `(‘mayor’). La salida de todas las otras líneas no se mostrará. Por ejemplo, aquí está el archivo de descripción de un algoritmo que realiza una prueba normalmente en un determinado campo (columna) de los atributos de una capa vectorial:

##layer=vector
##field=field layer
##nortest=group
library(nortest)
>lillie.test(layer[[field]])

The output of the last line is printed, but the output of the first is not (and neither are the outputs from other command lines added automatically by QGIS).

Si su algoritmo crea algún tipo de gráficos (utilizando el método plot()), añada la siguiente línea:

##showplots

This will cause QGIS to redirect all R graphical outputs to a temporary file, which will be opened once R execution has finished.

Tanto los resultados gráficos como de consola, se mostrará en el gesto de resultados de procesamiento.

For more information, please check the script files provided with SEXTANTE. Most of them are rather simple and will greatly help you understand how to create your own scripts.

Nota

rgdal and maptools libraries are loaded by default, so you do not have to add the corresponding library() commands (you just have to make sure that those two packages are installed in your R distribution). However, other additional libraries that you might need have to be explicitly loaded. Just add the necessary commands at the beginning of your script. You also have to make sure that the corresponding packages are installed in the R distribution used by QGIS. The processing framework will not take care of any package installation. If you run a script that requires a package that is not installed, the execution will fail, and Processing will try to detect which packages are missing. You must install those missing libraries manually before you can run the algorithm.

GRASS

Configuring GRASS is not much different from configuring SAGA. First, the path to the GRASS folder has to be defined, but only if you are running Windows. Additionaly, a shell interpreter (usually msys.exe, which can be found in most GRASS for Windows distributions) has to be defined and its path set up as well.

By default, the processing framework tries to configure its GRASS connector to use the GRASS distribution that ships along with QGIS. This should work without problems in most systems, but if you experience problems, you might have to configure the GRASS connector manually. Also, if you want to use a different GRASS installation, you can change that setting and point to the folder where the other version is installed. GRASS 6.4 is needed for algorithms to work correctly.

Si se utiliza Linux, hay que asegurarse de que GRASS está correctamente instalado y que se puede ejecutar sin problemas desde una consola.

GRASS algorithms use a region for calculations. This region can be defined manually using values similar to the ones found in the SAGA configuration, or automatically, taking the minimum extent that covers all the input layers used to execute the algorithm each time. If the latter approach is the behaviour you prefer, just check the Use min covering region option in the GRASS configuration parameters.

The last parameter that has to be configured is related to the mapset. A mapset is needed to run GRASS, and the processing framework creates a temporary one for each execution. You have to specify if the data you are working with uses geographical (lat/lon) coordinates or projected ones.

GDAL

No additional configuration is needed to run GDAL algorithms. Since they are already incorporated into QGIS, the algorithms can infer their configuration from it.

Caja de Herramientas de Orfeo

Orfeo Toolbox (OTB) algorithms can be run from QGIS if you have OTB installed in your system and you have configured QGIS properly, so it can find all necessary files (command-line tools and libraries).

As in the case of SAGA, OTB binaries are included in the stand-alone installer for Windows, but they are not included if you are runing Linux, so you have to download and install the software yourself. Please check the OTB website for more information.

Once OTB is installed, start QGIS, open the processing configuration dialog and configure the OTB algorithm provider. In the Orfeo Toolbox (image analysis) block, you will find all settings related to OTB. First, ensure that algorithms are enabled.

Entonces, configurar la ruta al directorio donde las aplicaciones de línea de comandos y las librerías de OTB se encuentran instaladas:

  • nix Normalmente, el directorio de aplicaciones de OTB apunta a `/usr/lib/otb/applications`` y el directorio con los programas de línea de comandos de OTB es `/usr/bin``.

  • win If you use the OSGeo4W installer, then install otb-bin package and enter C:\OSGeo4W\apps\orfeotoolbox\applications as OTB applications folder and C:\OSGeo4W\bin as OTB command line tools folder. These values should be configured by default, but if you have a different OTB installation, configure them to the corresponding values in your system.

TauDEM

To use this provider, you need to install TauDEM command line tools.

Windows

Please visit the TauDEM homepage for installation instructions and precompiled binaries for 32-bit and 64-bit systems. IMPORTANT: You need TauDEM 5.0.6 executables. Version 5.2 is currently not supported.

Linux

There are no packages for most Linux distributions, so you should compile TauDEM by yourself. As TauDEM uses MPICH2, first install it using your favorite package manager. Alternatively, TauDEM works fine with Open MPI, so you can use it instead of MPICH2.

Download TauDEM 5.0.6 source code and extract the files in some folder.

Abrir el archivo linearpart.h , y después de la línea

#include "mpi.h"

añadir una nueva linea con

#include <stdint.h>

y obtendrá

#include "mpi.h"
#include <stdint.h>

Guardar los cambios y cerrar el archivo. Ahora abir tiffIO.h, buscar la línea #include "stdint.h" y sustituir las comillas ("") con <>, para obtener

#include <stdint.h>

Save the changes and close the file. Create a build directory and cd into it

mkdir build
cd build

Configure your build with the command

CXX=mpicxx cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..

and then compile

make

Finally, to install TauDEM into /usr/local/bin, run

sudo make install