Batch Processing using Processing Framework (QGIS2)¶
Avertissement
A new version of this tutorial is available at Traitement par lots en utilisant le framework de traitement (QGIS3)
QGIS 2.0 introduced a new concept called Processing Framework. Previously known as Sextante, the Processing Framework provides an environment within QGIS to run native and third-party algorithms for processing data. It contains a nice batch processing interface that allows one to execute an algorithm on several layers easily. Batch processing is a useful tool that can save manual effort and help you automate repetitive tasks.
Description de l’exercice¶
We will take several global vector layers and clip them to the extent of Africa in a single batch command.
Autres compétences que vous allez développer¶
Dissolve (merge) polygons from a layer that have the same attribute.
Récupérer les données¶
Natural Earth has several global vector layers. Download the following layers
Once downloaded, unzip and extract all the shapefiles in a single folder.
Data Source: [NATURALEARTH]
Procédure¶
Go to
.
![../_images/1160.png](../_images/1160.png)
Browse to the downloaded Admin 0 Countries shapefile
ne_10m_admin_0_countries.shp
and click Open.
![../_images/2132.png](../_images/2132.png)
As our task is to clip the global layers to the boundary of Africa, we need to first prepare a layer containg a polygon for the entire continent. The countries layer has an attribute called CONTINENT. We can use a geoprocessing concept called Dissolve to merge all countries that have the same continent value and merge them to a single polygon.
![../_images/368.png](../_images/368.png)
Open the Dissolve tool from .
![../_images/438.png](../_images/438.png)
Select
ne_10m_admin_0_countries
as the Input vector layer. The Dissolve field would beCONTINENT
. Name the output file ascontinents.shp
and check the box next to Add result to convas.
Note
If you want to merge ALL polygons regardless of their attributes, you can select – Dissolve All – as the Dissolve field. This will combine all polygons in the layer and give you a single aggregate polygon.
![../_images/537.png](../_images/537.png)
The dissolve processing may take a while. Once the process finishes, you will see the new
continent
layer added to QGIS. Use the Select Single Feature tool from the toolbar and click on Africa to select the polygon representing the continent.
![../_images/636.png](../_images/636.png)
Right-click the
continents
layer and select Save Selection As….
![../_images/736.png](../_images/736.png)
Name the output file as
africa.shp
. Since we are only interested in the shape of the continent and not any attributes, you may check the Skip attribute creation. Make sure the Add saved file to map box is checked and click OK.
![../_images/835.png](../_images/835.png)
Now you will have the
africa
layer loaded in QGIS containing a single polygon for the entire continent. Now, it’s time to start our batch clip process. Open .
![../_images/936.png](../_images/936.png)
Browse all available algorithms and find the Clip tool from . You may also use the Search box to easily find the algorithm as well.
![../_images/1043.png](../_images/1043.png)
Right-click the Clip algorithm and select Execure as batch process.
![../_images/1161.png](../_images/1161.png)
In the Batch Processing dialog, the first tab is Parameters where we define out inputs. Click the … next to the first row in the Input layer column.
![../_images/1246.png](../_images/1246.png)
Browse to the directory containing the global transportation layers that you had downloaded. Hold the Ctrl key and select all the layers that you want to clip. You may also use Shift or Ctrl-A to make multiple selection. Click Open.
![../_images/1344.png](../_images/1344.png)
You will notice that the Input layer columns will be auto-populated with all layers you had selected. You may use Add row button to add more rows and define more inputs. Next, we need to select the layer containing the boundary to clip our input layers. Click the … button for the first row and add the
africa.shp
Clip layer. Since the clip layer is the same for all our inputs, you can double-click the column header Clip layer and the same layer will be auto-filled for all the rows. Next, we need to define our outputs. Click the … buton next to the first row in the Clipped column.
![../_images/1441.png](../_images/1441.png)
Browse the the directory where you want your output layers. Type the filename as
clipped_
and click Save.
![../_images/1538.png](../_images/1538.png)
You will see a new Autofill settings dialog pop up. Select Fill with parameter values as the Autofill mode. Select Parameter to use as Input layer. This setting will add the input file name to the output along with the specified
output_
filename. This is important to ensure all the output files have unique names and they do not overwrite each other.
![../_images/1636.png](../_images/1636.png)
Now we are ready to start the batch procesing. Click Run.
![../_images/1733.png](../_images/1733.png)
The clip algorithm will run for each of the inputs and create output files are we have specified. Once the batch process finishes, you will see the layers added to QGIS canvas. As you will notice, all the global layers are properly clipped to the continent boundary that we had specified.
![../_images/1831.png](../_images/1831.png)
If you want to report any issues with this tutorial, please comment below. (requires GitHub account)