.

Los Comandos QGIS

El procesado incluye una herramienta practica que le permite ejecutar algoritmos sin tener que utilizar la caja de herramientas, pero tan solo escribir el nombre del algoritmo que se desee ejecutar.

Esta herramienta es conocida como Comandos GQIS, y esto es solo una sencilla caja de texto con autocompletado donde se escribe el nombre del comando que se desee ejecutar.

../../../_images/commander1.png

The QGIS Commander win

The Commander is started from the Analysis menu or, more practically, by pressing Shift + Ctrl + M (you can change that default keyboard shortcut in the QGIS configuration if you prefer a different one). Apart from executing Processing algorithms, the Commander gives you access to most of the functionality in QGIS, which means that it gives you a practical and efficient way of running QGIS tasks and allows you to control QGIS with reduced usage of buttons and menus.

Moreover, the Commander is configurable, so you can add your custom commands and have them just a few keystrokes away, making it a powerful tool to help you become more productive in your daily work with QGIS.

Comandos disponibles

Los comandos disponibles en el Comandante caen en la siguiente categoría:

  • Algoritmos de procesado. Estos se muestran como Algoritmo de procesamiento: <nombre del algoritmo>.

  • Menu items. These are shown as Menu item: <menu entry text>. All menus items available from the QGIS interface are available, even if they are included in a submenu.
  • Funciones Python. Puede crear funciones cortas en Python que serán entonces incluidas en la lista de comandos disponibles. Ellos se muestran como Function: <nombre de la función>.

Para ejecutar cualquiera de los anteriores, inicie escribiendo y a continuación, seleccione el elemento de la lista de comandos disponibles que aparecen después de filtrar toda la lista de comandos con el texto que ha introducido.

In the case of calling a Python function, you can select the entry in the list, which is prefixed by Function: (for instance, Function: removeall), or just directly type the function name (``removeall in the previous example). There is no need to add brackets after the function name.

Crear funciones personalizadas

Custom functions are added by entering the corresponding Python code in the commands.py file that is found in the .qgis/sextante/commander directory in your user folder. It is just a simple Python file where you can add the functions that you need.

The file is created with a few example functions the first time you open the Commander. If you haven’t launched the Commander yet, you can create the file yourself. To edit the commands file, use your favorite text editor. You can also use a built-in editor by calling the edit command from the Commander. It will open the editor with the commands file, and you can edit it directly and then save your changes.

Por ejemplo, puede añadir la siguiente función, la cual borre todas las capa:

from qgis.gui import *

def removeall():
    mapreg = QgsMapLayerRegistry.instance()
    mapreg.removeAllMapLayers()

Una vez que se haya añadido la función, estará disponible en Comandos, y puede invocarlo escribiendo removeall. No hay necesidad de hacer algo más aparte de escribir la función en sí.

Las funciones pueden recibir parámetros. Añadir *args a la definición de su función para recibir argumentos. Cuando llame a la función desde Comandos, los parámetros tienen que ser pasados separados por espacios.

Aquí esta un ejemplo de una función que carga una capa y toma un parámetro con el nombre del archivo de la capa cargada.

import processing

def load(*args):
  processing.load(args[0])

If you want to load the layer in /home/myuser/points.shp, type load /home/myuser/points.shp in the Commander text box.