QGIS Model Designer offers powerful functionality for automating workflows. Many workflows are based on conditional logic that can generate different outputs based on the inputs provided. This post shows how to setup a QGIS model that can skip certain steps if those optional inputs are not provided. This is achieved using the Conditional branch algorithm in the QGIS Model Designer.
Here’s the example workflow we want to implement
- Given a buildings layer and a boundary layer, create a layer with building polygons at least 50m away from the boundary. This will be the final output if no other inputs are provided.
- Optionally, if a roads layer has been provided, further process the data and create a layer with buildings polygons that are both 50m away from the boundary and within 25m of a road segment.
The key is to use an expression that checks if the roads input is NULL and selects the appropriate branch of the model to process. Below is the diagram showing the final model.

We will go through the step-by-step process of building this model. You will find a link to download a GeoPackage file containing the final model and the sample dataset at the end of the post.
We start with a QGIS project containing 3 layers.
- A polygon layer boundary defining the region of interest
- A polygon layer buildings containing building footprints
- An optional line layer roads containing roads

We open the Model Designer and define 3 inputs of type Vector Layer. When defining the inputs, we select appropriate geometry type and whether the input is Mandatory or not. We keep the roads input as optional by unchecking the mandatory option.

We now create a conditional branch to split the workflow based on whether the roads input was provided. Add a new algorithm from Modeler Tools → Conditional branch. Create a new branch named Roads are provided and click the Expression button.

You will see the layer variables at the top of the Expression editor. Select the variable for the optional input for your model. In our case it is named @roads, so we write an expression as @roads is not NULL.

Similarly create another branch Roads are not provided with the expression @roads is NULL.

The conditional branches are now ready to be used. First we add an Intersection algorithm to generate the output in case the roads are not provided. Since we want to select all the buildings 50m away from the boundary, we first create a Buffer with a distance of -50 meters to buffer the boundary inwards. Then we calculate the Intersection of this buffer with the buildings layer. This will create the desired output. To ensure this output is generated only in the case when the roads are not provided, you need to add a dependency.

Choose the condition Roads are not provided as the dependency for this algorithm.

We repeat the Intersection step, but this time configure it to use the roads input.

Choose the condition Roads are provided as the dependency for this algorithm.

Continue with the additional processing steps of buffering the roads and calculating the intersection using the output from this branch. Here’s what the finished model looks like.
Tip: Use the Edit → Add Group Box to add the box around selected steps to visually group them and Edit → Snap Selected Components to Grid to align the boxes to give a clean professional appearance to your models.

Let’s test the model. First we run it without giving any input for the Roads parameter.

We get the output layer of buildings that are 50m away from the boundary.

Next, we run the model again specifying the roads layer as an input for the Roads parameter.

This time we get a different output with the buildings that are both 50m away from the boundary and also within 25m from a road.

If you want to try out the model yourself, download the data.gpkg file that contains the data layers and a QGIS Project containing the model. To open the project, locate the data.gpkg in the QGIS Browser, expand it and double-click the Conditional_Input project. Once the project is opened, you will see the model in Processing toolbox → Project models → Conditional_Input.
Dara credit: OpenStreetMap Contributors.

If you are interested in learning more QGIS Automation techniques, please check out our Advanced QGIS course which is freely available for self-study.
