QGIS-A04: QGIS Graphical Modeler v3.28

4. QGIS Graphical Modeler

4.1. Introduction

This module covers the Graphical Modeler, which allows you to build and save process models containing one or more steps using a graphical interface.

Once a model has been built, it can be:

  • Run from within QGIS, with different inputs

  • Run as a standalone process using Python, for example from a batch file

  • Made available as a shared resource

The Modeler can make use of any processes in the Processing Toolbox, so it's a useful tool for automating most things that QGIS can do.

4.2. Summary

The module shows you how to build a short workflow, so that it can be stored, repeated and shared.

The aim of the example is to take house price data from Bath in the UK, and represent it as a choropleth-styled map based on a grid.

The steps in the process are:

  • Load CSV file of house sale prices

  • Process the data to convert the Price field from a string to an integer

  • Create a vector grid

  • Join the house price data with a grid layer, summarising the individual price data as part of the process

Once these steps have been completed, you should have both a point layer of all house sales, and summary house price data for each cell in a grid overlay.

To get started: 

  1. Open a new project in QGIS

  2. Load ...Data/Vector/House Price Paid Data - Land Registry Bath 2016.csv as Delimited Text, setting the Geometry Definition to No geometry

  3. Open the attribute table and review the data

  4. Save the project in a suitable location (e.g. ../Advanced/graphicalmodeler.qgz)

4.3. Create a point layer from CSV

We'll now create a model to do the processing.

  1. Go to Processing > Graphical Modeler

  2. In Model Properties, complete the Name and Group fields with appropriate names (e.g. House prices and QGIS Training)

  3. Go to Model > Save Model in Project to save the model to current QGIS project 

  4. Select a processing tool to spatialise the rows in the table

    1. In the Algorithms tab, search for points layer

    2. Select the QGIS algorithm Create points layer from table

    3. Complete the dialogue as shown below to create a points layer from the layer - you will need to type in the values for X field and Y field rather than use the drop-downs, and set the CRS to EPSG:4326, as the values in the file are for latitude and longitude

  5. Click OK - the model should now look something like this:

  6. Click the Run button to show the dialogue below 

  7. Click Run to run the model

  8. You will see a new layer on the map, Points with geom - look at the layer to see that it's correct

  9. Right-click > Remove on the new layer to clean up before moving to the next stage

4.4. Add a vector grid to use for analysis

Now edit the model to overlay a vector grid which we can use to analyse the point vector data.

  1. In the Algorithms tab, search for grid and select Create grid

  2. Complete the dialogue as shown below - this will create a grid of 1km squares which covers the extent of the point layer

  3. Note that you'll need to click on the button below Grid extent and choose Algorithmic output

  4. Save and re-run the model

  5. You should now have a 500m polygon hex grid overlaying the point layer

  6. Remove all the layers except the original CSV layer, and save the project

4.5. Join the house price points to the grid polygons and summarise

  1. In the Algorithms tab, search for join

  2. Double click on Join attributes by location (summary)

  3. Complete the dialogue as below - note that:

    1. Under Base layer and Join layer, click on the 123 button and select Algorithmic output to see the dropdown

    2. for Geometric predicate you will need to click the three dots on the right and choose Contains

    3. for Summaries to calculate, click the three dots and choose mean

  4. Save and run the model

  5. You should see a new grid layer, with the a mean attribute for the house prices in each grid unit

4.6. Results

By this time, you should have a model which looks like this:

and your main QGIS interface should look something like this:

4.7. Add some styling

We've now got a process which creates a hex grid containing summary statistics on house prices for each hexagon square, so to make it useful we can add some styling.

  1. Add a WMS layer of background mapping - for example using QuickMapServices

  2. Remove all the layers except Grid with price, and right-click > Properties > Symbology, then select a Graduated style and use the price_mean column, with Mode set to Equal Interval to get the result below 

  3. Once you have created the styling, save it from the symbology dialogue under Style >  Save Style with an appropriate filename

  4. Tidy up the model by removing all the intermediate layer outputs except the last, so it looks like this

  5. Save the model, and save the project

4.8. Automatically applying style

Once the style has been created, you can set the model to apply it every time the model is run.

  1. In the Processing Toolbox, navigate to Project Models > Training > House Prices and right-click > Edit Rendering Styles for Outputs

  2. In the dialogue, select your saved style for Grid with price and click OK

  3. Right-click the model > Execute, then click Run - the model will run and the style will be applied to the final grid