Important

Translation is a community effort you can join. This page is currently translated at 57.14%.

27.8. Utilisation du traitement à partir de la ligne de commande

QGISQGIS est livré avec un outil appelé QGIS Processing Executor qui vous permet d’appeler des algorithmes de traitement et des modèles (fournis par défaut ou via des extensions) directement depuis la ligne de commande sans avoir à lancer QGIS lui-même.

Exécutez qgis_process en ligne de commande et vous devriez obtenir :

QGIS Processing Executor - 3.27.0-Master 'Master' (3.27.0-Master)
Usage: C:\OSGeo4W\apps\qgis-dev\bin\qgis_process.exe [--help] [--version] [--json] [--verbose] [--no-python] [command] [algorithm id, path to model file, or path to Python script] [parameters]

Options:

  --help or -h      Output the help
  --version or -v   Output all versions related to QGIS Process
  --json            Output results as JSON objects
  --verbose         Output verbose logs
  --no-python       Disable Python support (results in faster startup)

Available commands:

  plugins          list available and active plugins
  plugins enable   enables an installed plugin. The plugin name must be specified, e.g. "plugins enable cartography_tools"
  plugins disable  disables an installed plugin. The plugin name must be specified, e.g. "plugins disable cartography_tools"
  list             list all available processing algorithms
  help             show help for an algorithm. The algorithm id or a path to a model file must be specified.
  run              runs an algorithm. The algorithm id or a path to a model file and parameter values must be specified.
                   Parameter values are specified after -- with PARAMETER=VALUE syntax.
                   Ordered list values for a parameter can be created by specifying the parameter multiple times,
                   e.g. --LAYERS=layer1.shp --LAYERS=layer2.shp
                   Alternatively, a '-' character in place of the parameters argument indicates that the parameters should be read from STDIN as a JSON object.
                   The JSON should be structured as a map containing at least the "inputs" key specifying a map of input parameter values.
                   This implies the --json option for output as a JSON object.
                   If required, the ellipsoid to use for distance and area calculations can be specified via the "--ELLIPSOID=name" argument.
                   If required, an existing QGIS project to use during the algorithm execution can be specified via the "--PROJECT_PATH=path" argument.

Note

Only installed plugins that advertise hasProcessingProvider=yes in their metadata.txt file are recognized and can be activated or loaded by qgis_process tool.

Indication

Before calling qgis_process on a system without window manager (e.g. a headless server), you should set:

export QT_QPA_PLATFORM=offscreen

La commande list peut être utilisée pour obtenir une liste de tous les fournisseurs et algorithmes disponibles.

qgis_process list

La commande help peut être utilisée pour obtenir des informations supplémentaires sur les commandes ou les algorithmes.

qgis_process help qgis:regularpoints

La commande run peut être utilisée pour exécuter un algorithme ou un modèle. Spécifiez le nom de l’algorithme ou un chemin d’accès à un modèle comme premier paramètre.

qgis_process run native:buffer -- INPUT=source.shp DISTANCE=2 OUTPUT=buffered.shp

Lorsque le paramètre requiert plusieurs valeurs, il faut définir la variable autant de fois que nécessaire.

qgis_process run native:mergevectorlayers -- LAYERS=input1.shp LAYERS=input2.shp OUTPUT=merged.shp

While running an algorithm a text-based feedback bar is shown, and the operation can be cancelled via CTRL+C.

The run command also supports further parameters.

  • --json formattera la sortie stdout selon une structure de type JSON.

  • --ellipsoid fixera l’ellipsoïde à celui qui est spécifié.

  • --distance_units utilisera les unités de distance spécifiées

  • --area_units utilisera les unités de surface spécifiées.

  • --project_path chargera le projet spécifié pour l’exécution de l’algorithme.

Complex input parameters, i.e. parameter types which are themselves specified as a dictionary type object for algorithms, are supported by qgis_process. To indicate that parameters will be specified via stdin, the qgis_process command must follow the format (with a trailing - in place of the usual arguments list).

qgis_process run algorithmId -

The JSON object must contain an « inputs » key, which is a map of the input parameter values. E.g.

echo "{'inputs': {'INPUT': 'my_shape.shp', 'DISTANCE': 5}}" | qgis_process run native:buffer -

Additionally, extra settings like the distance units, area units, ellipsoid and project path can be included in this JSON object:

{
 'ellipsoid': 'EPSG:7019',
 'distance_units': 'feet',
 'area_units': 'ha',
 'project_path': 'C:/temp/my_project.qgs'
 'inputs': {'DISTANCE': 5, 'SEGMENTS': 8 ... }
}

Specifying input parameters via stdin implies automatically the JSON output format for results.