QGIS 3.14 (Pi) introduced the qgis_process tool – a command-line executable that “allows users to run processing algorithms (both built-in, and those provided by plugins) directly from the console” developed by Nyall Dawson and sponsored by the Swedish User Group. You can find the Pull Request of the feature here.
Being run straight from the console and outside the QGIS GUI application, qgis_process provides users the ability to harness the full power of the QGIS processing algorithms through batch files, shell scripts, and other operating system tools. This is also useful if you want to use QGIS processing algorithms externally without needing to write Python (or PyQGIS) scripts.
Currently, the tool has several commands:
--param=value syntax. For example:
qgis_process run native:centroids --INPUT="my_shapefile.shp" --OUTPUT="centroids.kml"
qgis_process run native:buffer --INPUT=/home/me/my.shp --DISTANCE=20 --OUTPUT=/home/me/buffered.shp
If you are on Linux, the tool can be accessed directly from the terminal. For Windows users, you can access the tool from the OSGeo4W shell (this usually comes installed with QGIS).
In my examples, I run this tool on a machine with a Pop! OS 20.04 (based on Ubuntu 20.04) operating system.
If you want to find what algorithms you can run, enter qgis_process list on the terminal.
If you want help for a specific algorithm (e.g. you want to know its parameters/arguments), enter qgis_process help algid on the terminal. algid refers to the id used by QGIS to identify the algorithm. Veterans and power users of the QGIS processing framework are probably already familiar with this. For beginners, these are the first items per line of the qgis_process list output and follows the format
qgis_process help native:dissolve
Take note of the Arguments listed by qgis_process help. These are the arguments/parameters that can be provided when running the algorithm. Some arguments/parameters are optional. To learn more about QGIS processing algorithms and their parameters, you can check the QGIS documentation or this list made by Thomas Gratier.
---------------- Arguments ---------------- INPUT: Input layer Argument type: source Acceptable values: - Path to a vector layer FIELD: Dissolve field(s) Argument type: field Acceptable values: - The name of an existing field - ; delimited list of existing field names OUTPUT: Dissolved Argument type: sink Acceptable values: - Path for new vector layer
For native: dissolve, we have INPUT, FIELD, and OUTPUT. Adding these arguments/parameters to the command is done via a
Let’s run a simple dissolve algorithm. First, add/export the QT_QPA_PLATFORM variable (for Linux).
Afterwards, run the algorithm.
qgis_process run native:dissolve --FIELD="" --INPUT="/path/to/input.vector" --OUTPUT="/path/to/output.vector"
In my example, I used a geojson containing features of municipalities of a province and dissolved them to have a geojson with just the feature of the province.
You can check your output by opening it in QGIS.
This work and its contents by Ben Hur S. Pintor is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Other works (software, source code, etc.) referenced in this website are under their own respective licenses.
This site is powered by Jekyll and hosted on Github (view source)