Batch Processing using Processing Framework (QGIS3)¶
The Processing Framework in QGIS 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.
Overview of the task¶
We will take several global vector layers and clip them to the extent of Africa in a single batch command.
Other skills you will learn¶
Create a Filter to remove unwanted features from a layer without creating a new layer.
Merge multiple layers into a single Geopackage file.
Get the data¶
Natural Earth has several global vector layers. Download the following layers
For convenience, you may directly download a geopackage containing the above layers from below:
Data Source: [NATURALEARTH]
Procedure¶
In the QGIS Browser Panel, locate the directory where you saved your downloaded data. Expand the
zip
or thegpkg
entry and select thene_10m_admin_0_countries
layer. Drag the layer to the canvas.
![../../_images/119.png](../../_images/119.png)
You will see the layer loaded in the Layers panel. As our task is to clip the global layers to the boundary of Africa, we need to first prepare a layer containg features only from that continent. Let’s look at the attribute table to see what column can be used to query features belonging to a particular continent. Right-click the
ne_10m_admin_0_countries
layer and select Open Attribute Table.
Примечание
Tip: You can also use the keyboard shortcut F6 to open the attribute table of the selected layer.
![../../_images/216.png](../../_images/216.png)
In the Attribute Table window, as you scroll horizontally, you will see that the data contains an attribute called CONTINENT. We can use this attribute to filter features.
![../../_images/314.png](../../_images/314.png)
Close the attribute table and return to the main QGIS window. Right-click the
ne_10m_admin_0_countries
layer and select Filter.
![../../_images/44.png](../../_images/44.png)
In the Query Builder window, select the CONTINENT field and click Sample. This will populate the Values panel with the a subset of values of that attribute from features. This step is useful to get an understanding of what type of values are present in your dataset. We can see that our dataset contains contains a value called Africa among others.
![../../_images/54.png](../../_images/54.png)
Now enter the expression in the Provider specific filter expression textbox. You can click the CONTINENT label, followed by = button and Africa label. Or you can type the following expression in the textbox. Click OK after entering the expression.
"CONTINENT" = 'Africa'
![../../_images/64.png](../../_images/64.png)
You will see that the map canvas now contains only the countries from Africa. Note the filter icon next to the layer name indicating that that layer a filter applied to it. If you wanted to see and use all the features from the layer, you can click the filter icon and clear the expression. For now, we will keep the filter so we can clip other layers to Africa.
![../../_images/74.png](../../_images/74.png)
We are now ready to run the batch process to clip the layers. Locate the natural earth global layers
ne_10m_railroads
,ne_10m_ports
andne_10m_urban_areas
in the QGIS Browser panel. Hold the Ctrl key and click each layer to select them. Once selected, drag them to the canvas.
![../../_images/84.png](../../_images/84.png)
Once the layers are loaded, you will notice that they are global layers and have features spanning all the countries. Now, it’s time to start our batch clip process to clip these layers to Africa. Open
.
![../../_images/94.png](../../_images/94.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/107.png](../../_images/107.png)
Right-click the Clip algorithm and select Execute as Batch Process.
![../../_images/1110.png](../../_images/1110.png)
In the Batch Processing dialog, the first tab is Parameters where we define our inputs. Each row in the table represents 1 processing task. Click Add row button to add a new row. As our task involves 3 layers, add 3 rows.
![../../_images/127.png](../../_images/127.png)
Click the … next to the first row in the Input layers column. Select Select from Open Layers.
![../../_images/136.png](../../_images/136.png)
In the Multiple selection dialog, check the 3 layers that we want to clip and click OK.
![../../_images/146.png](../../_images/146.png)
You will notice that the Input layer columns will be auto-populated with all layers you had selected. Next, we need to select the layer containing the boundary to clip our input layers. Click the … button for the first row under Overlay layer column and select Select form Open Layers.
![../../_images/156.png](../../_images/156.png)
In the Multiple selection dialog, check
ne_10m_admin_0_countries
and click OK.
![../../_images/166.png](../../_images/166.png)
Since the clip layer is the same for all our inputs, a handy shortcut is to double-click the column header Overlay layer and the same layer will be auto-filled for all the rows.
![../../_images/176.png](../../_images/176.png)
Next, we need to define our outputs. Click the … buton next to the first row in the Clipped column.
![../../_images/184.png](../../_images/184.png)
Browse the the directory where you want your output layers. Type the filename as
clipped_
and click Save.
![../../_images/194.png](../../_images/194.png)
You will see a new Autofill settings dialog pop up. Select
Fill with parameter values
as the Autofill mode. SelectInput layer
as the Parameter to use. This setting will add the input file name to the output along with the specifiedclipped_
filename. This is important to ensure all the output files have unique names and they do not overwrite each other.
![../../_images/204.png](../../_images/204.png)
Now we are ready to start the batch procesing. Make sure to check Load layers on completion and click Run.
![../../_images/217.png](../../_images/217.png)
The clip algorithm will run for each of the inputs and create output files are we have specified. Once the batch process finishes, click Close to return to QGIS.
Примечание
Tip: QGIS can now run Processing tasks in the background without blocking the user interface. So if your batch process is taking long, you can close the dialog and continue to work on other tasks in QGIS while the process keeps running in the background.
![../../_images/224.png](../../_images/224.png)
Back in the main QGIS window, 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/234.png](../../_images/234.png)
We have accomplished the task of clipping multiple layers in a batch. But QGIS3 has another handy feature that will help you save and deliver the result in a more efficient way. If you wanted to deliver the clipped layers to someone, you would zip the individual files outside of QGIS. A better option to to package the output layers in a single Geopackage. In the QGIS Browser, locate the clipped output layers. You may have to click the Refresh button to see the newly added files.
![../../_images/244.png](../../_images/244.png)
Hold Ctrl key and select the layers. Drag them to the canvas to load them in QGIS.
![../../_images/254.png](../../_images/254.png)
In Processing Toolbox, locate the tool.
![../../_images/263.png](../../_images/263.png)
In the Package layers dialog, click the … button next to Input layers.
![../../_images/274.png](../../_images/274.png)
In the Multiple selection dialog, check the
clipped_ne_10m_ports
,clipped_ne_10m_railroads
andclipped_ne_10m_urban_areas
layers. Click OK.
![../../_images/284.png](../../_images/284.png)
Once the input layers are selected, click the … next to Destination Geopackage and choose Save To File.
![../../_images/293.png](../../_images/293.png)
Enter the output file name as
clipped_layers
.
![../../_images/303.png](../../_images/303.png)
Click Run to start the packaging process.
![../../_images/315.png](../../_images/315.png)
Once the process finishes, you will see a new geopackage file in your QGIS Browser containing all the clipped output layers. This is a single file on your computer that contains all the output layers.
![../../_images/322.png](../../_images/322.png)
If you want to report any issues with this tutorial, please comment below. (requires GitHub account)