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:Â
Open a new project in QGIS
Load ...Data/Vector/House Price Paid Data - Land Registry Bath 2016.csv as Delimited Text, setting the Geometry Definition to No geometry
Open the attribute table and review the data
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.
Go to Processing > Graphical Modeler
In Model Properties, complete the Name and Group fields with appropriate names (e.g. House prices and QGIS Training)
Go to Model > Save Model in Project to save the model to current QGIS projectÂ
Select a processing tool to spatialise the rows in the table
In the Algorithms tab, search for points layer
Select the QGIS algorithm Create points layer from table
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
Click OK - the model should now look something like this:
Click the Run button to show the dialogue belowÂ
Click Run to run the model
You will see a new layer on the map, Points with geom -Â look at the layer to see that it's correct
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.
In the Algorithms tab, search for grid and select Create grid
Complete the dialogue as shown below - this will create a grid of 1km squares which covers the extent of the point layer
Note that you'll need to click on the button below Grid extent and choose Algorithmic output
Save and re-run the model
You should now have a 500m polygon hex grid overlaying the point layer
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
In the Algorithms tab, search for join
Double click on Join attributes by location (summary)
Complete the dialogue as below - note that:
Under Base layer and Join layer, click on the 123 button and select Algorithmic output to see the dropdown
for Geometric predicate you will need to click the three dots on the right and choose Contains
for Summaries to calculate, click the three dots and choose mean
Save and run the model
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.
Add a WMS layer of background mapping - for example using QuickMapServices
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Â
Once you have created the styling, save it from the symbology dialogue under Style >Â Save Style with an appropriate filename
Tidy up the model by removing all the intermediate layer outputs except the last, so it looks like this
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.
In the Processing Toolbox, navigate to Project Models > Training > House Prices and right-click > Edit Rendering Styles for Outputs
In the dialogue, select your saved style for Grid with price and click OK
Right-click the model > Execute, then click Run - the model will run and the style will be applied to the final grid