file.exists("suitability.gpkg")[1] TRUE
Barry Rowlingson
Download the Workshop Materials and extract from the zip file for the datasets etc needed here. Layers in suitability.gpkg are from OpenStreetMap data, available under the Open Database License, except for the tracks layer which I created manually. The land use raster was generated using the European Union’s Copernicus Land Monitoring Service information. The elevation data was derived from SRTM tiles which were joined and transformed to the given coordinate system.
Start an R session with its working folder set to the folder that the unzip created. Check you are in the right place by testing if this GeoPackage file exists. If this returns FALSE then use setwd or restart your R session with a new project in the right folder.
You’ll also need a version 3.xx of QGIS installed and the qgisprocess package. Get that package from CRAN in the usual way - install.packages("qgisprocess") or your IDE may have a menu option.
To start using the package, attach it in the usual way via the library function:
Attempting to load the package cache ... Success!
QGIS version: 3.44.15-Solothurn
Having access to 739 algorithms from 9 QGIS processing providers.
Run `qgis_configure(use_cached_data = TRUE)` to reload cache and get more details.
>>> Run `qgis_enable_plugins()` to enable 2 disabled plugins and access their algorithms: DataPlotly,
Mergin
You’ll see something like that depending on what QGIS add-ons you may have. Notice that because it takes a few seconds to get the list of algorithms from QGIS it saves a cache of the current setup and uses that until you tell it to rescan, which you have to do if you install more algorithms.
This message is now telling me (you might see something different, depending on what you’ve got installed with QGIS) that I have around 730 functions I can call from R. But what are they?
The gateway function to the QGIS “algorithms” is qgis_search_algorithms - it takes a regular expression argument and finds all the algorithms that match the expression. So to find any algorithms that have “buffer” in their title, you need to use something like this to match “Buffer” and “buffer”:
# A tibble: 11 × 5
provider provider_title group algorithm algorithm_title
<chr> <chr> <chr> <chr> <chr>
1 gdal GDAL Vector geoprocessing gdal:buffervectors Buffer vectors
2 gdal GDAL Vector geoprocessing gdal:onesidebuffer One side buffer
3 grass GRASS Raster (r.*) grass:r.buffer r.buffer
4 grass GRASS Raster (r.*) grass:r.buffer.lowmem r.buffer.lowmem
5 grass GRASS Vector (v.*) grass:v.buffer v.buffer
6 native QGIS (native c++) Vector geometry native:buffer Buffer
7 native QGIS (native c++) Vector geometry native:bufferbym Variable width buffer (by M value)
8 native QGIS (native c++) Vector geometry native:multiringconstantbuffer Multi-ring buffer (constant distance)
9 native QGIS (native c++) Vector geometry native:singlesidedbuffer Single sided buffer
10 native QGIS (native c++) Vector geometry native:taperedbuffer Tapered buffers
11 native QGIS (native c++) Vector geometry native:wedgebuffers Create wedge buffers
R can do buffers round spatial features, but I don’t think it can do tapered buffers. Let’s try that.
There’s a line layer in the GeoPackage containing some tracks. Use the sf package to read the layer, and then plot it. There’s only one attribute, the lake name, so plotting the spatial object will give you a categorical label.
Reading layer `tracks' from data source
`/home/rowlings/Work/Workshops/FOSS4GUK/2026/rqgis_workshop/Worksheets/Site_Suitability/Site_Suitability/suitability.gpkg'
using driver `GPKG'
Simple feature collection with 3 features and 1 field
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: 3473801 ymin: 3539852 xmax: 3496677 ymax: 3573783
Projected CRS: ETRS89-extended / LAEA Europe

Next we need to find out what arguments the tapered buffer algorithm needs. There’s another qgisprocess function for that, and we feed it the algorithm label from the search list.
# A tibble: 5 × 6
name description qgis_type default_value available_values acceptable_values
<chr> <chr> <chr> <list> <list> <list>
1 INPUT Input layer source <NULL> <NULL> <chr [1]>
2 START_WIDTH Start width number <dbl [1]> <NULL> <chr [3]>
3 END_WIDTH End width number <int [1]> <NULL> <chr [3]>
4 SEGMENTS Segments number <int [1]> <NULL> <chr [3]>
5 OUTPUT Buffered sink <NULL> <NULL> <chr [1]>
Now we know enough to run the algorithm - lets make tapered buffers that start at 0 and end at 1km width. We can leave the other input setting (SEGMENTS) as default, and we don’t specify the OUTPUT setting.
Argument `SEGMENTS` is unspecified (using QGIS default value).
Using `OUTPUT = qgis_tmp_vector()`
This returned object, tbrun, isn’t a spatial object with the buffers in it. The output has been written to a temporary file, and to get that into R we need to use st_read again. The name of the output file is stored in the $OUTPUT component, as seen in the argument specs above. We can read this in and plot it.
Reading layer `file1f9c9e63fc5410' from data source `/tmp/Rtmp4qgR4C/file1f9c9e4efe413a/file1f9c9e63fc5410.gpkg' using driver `GPKG'
Simple feature collection with 3 features and 1 field
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 3473786 ymin: 3539852 xmax: 3496677 ymax: 3573783
Projected CRS: ETRS89-extended / LAEA Europe

The qgisprocess package works by first writing your spatial object to a file and then calling the qgis_process command-line utility which reads that file. You can run it directly on a layer from a file if you don’t need the source data in R at first. For example the same tapered buffer can be computed with:
Argument `SEGMENTS` is unspecified (using QGIS default value).
Using `OUTPUT = qgis_tmp_vector()`
This means if you want to run several QGIS algorithms you don’t need the overhead of reading into R each time. Let’s take the tapered buffers and compute their “roundness” using another QGIS algorithm. We’ll read this final result in:
Using `OUTPUT = qgis_tmp_vector()`
Simple feature collection with 3 features and 2 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 3473786 ymin: 3539852 xmax: 3496677 ymax: 3573783
Projected CRS: ETRS89-extended / LAEA Europe
lake roundness geom
1 Coniston 0.17513326 MULTIPOLYGON (((3473786 354...
2 Windermere 0.09712733 MULTIPOLYGON (((3482805 354...
3 Ullswater 0.12938559 MULTIPOLYGON (((3488721 356...
You can see that the tapered buffers are not very round - a roundness of 1 is a circle and 0 is a flat line!
That’s the basics of qgisprocess:
qgis_search_algorithmsqgis_show_helpto learn about what it does, and its arguments and defaultsqgis_get_argument_specsqgis_run_algorithmSo you’re an ace R spatial guru, and can do everthing with the sf, terra and tmap packages and friends, right? Perhaps you could even write a tapered buffer function that does what the QGIS algorithm above does? (Computing the “roundness” is easier - its \(4\pi A/P^2\) where \(A\) is the area and \(P\) is the perimeter. Try it!). Why use QGIS algorithms when R code could be faster and not need a round-trip to files as an overhead?
Well, not everyone is an R expert. Suppose you are working with a GIS team who have their job, and they can do it using QGIS, but then they need to hand something off to you as the R statistics expert. In this hypothetical case study your team need to define around 50 sample point locations for a survey within an area based on a bunch of conditions. They’ve provided a QGIS project, a GeoPackage, and some raster layer files with everything needed.
Start QGIS and load the suitability.qgz project file - you might be able to double-click the file to start QGIS from your OS with it, or use the Project... and Open options in QGIS’ menu.
You should see a map looking something like this.

This shows the land use categories over a shaded elevation model in Cumbria, together with the boundary of the protected area.
The site for the study must be an area of at least 1 km2 of broad-leaved forest, within the protected area, and with a roundness value over 0.25, because non-round areas can be difficult to create sample points in. The GIS team have kindly provided a model that will generate these candidate areas for you. In addition to those constraints, the model will also compute the mean and standard deviation of the elevation and the roughness, since these might inform the final site selection. The model diagram looks like this.

The model is bundled in with the project. If you look down the main Project menu you will see a Models item, and from there you can choose the SiteSelection model and Execute. Up comes an input dialog. Set the parameters like this so the land use, elevation, and protected areas refer to the matching layers in the project. The defaults for AreaMin, RoundnessThreshold and SiteClass should all be left - class 23 is broad-leaved forest. You can look this up from the layer symbology.

Run the model by clicking the Run button. QGIS should think and quickly produce a new layer, called LargeRound which satisfies the site selection criteria, producing in this case six sites which I’ve styled in orange and disabled a few layers for clarity to produce this.

Its great that we can run this from QGIS, but we want to run it from R so we can do more with the process. For this we can use qgisprocess as described above, but there’s a few steps we need to do first.
Models stored with project files can’t be accessed from the qgis_process command line and so can’t be accessed from the qgisprocess package in R. I’ve put a feature request in for this so maybe one day this step won’t be needed. To get the model accessible we have to save it in our profile folder.
In the Processing Toolbox find the Project models menu and expand it to see the SiteSelection model. Right-click and select Edit Model.... The model diagram should appear. Save the model (Control-S or the save icon or menu item) and it should prompt with your profile path and a folder that ends with something like processing/models/. It should save with a .model3 extension.

This done, the model should now appear also in the Models section of the Processing Toolbox. This is in your profile and so should be visible from qgisprocessing.
Now get R running or return to your R session. Do library(qgisprocess) if you haven’t already and let’s find the algorithm for the model:
# A tibble: 0 × 5
# ℹ 5 variables: provider <chr>, provider_title <chr>, group <chr>, algorithm <chr>, algorithm_title <chr>
There are no rows in this output, because the algorithm was not found. This is because the cache that qgisprocess uses isn’t up to date. We can fix that by running qgis_configure to update its cache with the use_cached_data argument:
This will print some informational messages and then we can search for the algorithm again.
# A tibble: 1 × 5
provider provider_title group algorithm algorithm_title
<chr> <chr> <chr> <chr> <chr>
1 model Models <NA> model:SiteSelection SiteSelection
Now we now the name (in the algorithm column) we can get the argument details:
# A tibble: 7 × 6
name description qgis_type default_value available_values acceptable_values
<chr> <chr> <chr> <list> <list> <list>
1 LandUse LandUse raster <NULL> <NULL> <chr [1]>
2 areamin AreaMin number <dbl [1]> <NULL> <chr [3]>
3 elevation Elevation raster <NULL> <NULL> <chr [1]>
4 protectedareas ProtectedAreas vector <NULL> <NULL> <chr [1]>
5 roundnessthreshold RoundnessThreshold number <dbl [1]> <NULL> <chr [3]>
6 siteclass SiteClass number <dbl [1]> <NULL> <chr [3]>
7 largeround LargeRound sink <NULL> <NULL> <chr [1]>
To run the QGIS algorithm in R we’ll first load the data into R as well. For that we need the terra package for raster data and sf for vectors.
You can check these have read in okay by plotting them, either using a plot function or the wonderful tmap package.
Instead of calling qgis_run_algorithm as before, this time we’ll first use qgis_function to make a callable function.
Using `largeround = qgis_tmp_vector()`
Simple feature collection with 6 features and 6 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 3475900 ymin: 3522200 xmax: 3492300 ymax: 3575400
Projected CRS: ETRS89 Lambert Azimutal Equal Area
DN roundness rough_mean rough_stdev elev_mean elev_stdev geom
1 23 0.2763438 78.92365 52.733363 162.79673 63.535105 POLYGON ((3477900 3575400, ...
2 23 0.2521031 54.38812 30.165184 215.26219 45.854136 POLYGON ((3487700 3568000, ...
3 23 0.4153884 50.53007 22.824800 340.23824 70.923442 POLYGON ((3479700 3567100, ...
4 23 0.3397051 11.24974 4.641378 18.29675 5.102975 POLYGON ((3476300 3535500, ...
5 23 0.2776360 21.87064 10.613330 42.45235 15.491745 POLYGON ((3489200 3525700, ...
6 23 0.3167773 32.81836 12.950766 81.17508 31.085238 POLYGON ((3490600 3524700, ...
(For some reason leaving out arguments here to get the default set in the model doesn’t work. This seems to be the behaviour of the underlying qgis_process executable, and I’m looking into it. This might be another bug.)
Now we have the sites object which we can map. Let’s use tmap because its so good. Install the tmap package if you don’t have it already, and try this:
We’ll choose the least rough polygon as the study site for our point sampling - it might make life easier for our field scientists!

Next we’ll use spatstat to generate fifty points with at least 100 metre spacing. In spatstat terms the study polygon is our “window”, and we’ll use the rSSI function to generate points with an inhibitory process that spaces them out. We can then convert this to an sf points data frame and transform it to OSGB grid coordinates.
We can now give our field team a list of sample coordinates, as well as a map of where to go, and we could save this as a GeoPackage for them to load into QGIS.
Here are some things you can try:
(Easy, if you got this far) Run the analysis using different land use codes, area thresholds, and roundness limits. What happens if no areas are selected? What other errors can you generate?
Try running it by specifying the spatial data as files and GDAL data sources, so you don’t need to load the data into R before passing it to qgis_run_algorithm.
Wrap this all up in an R function called select_site that takes the same arguments as the model, but gets the default values from the qgis_get_argument_specs data frame - they’re in the default_value column. You’ll need to know how to handle arguments in R, and how to extract the default values from this column which is a list of values.
(Hard) Write the selection method in pure R, and test it against the QGIS model version. You’ll need to extract areas of rasters by class, convert to polygons, compute roundness and so on. Perhaps you’ll be grateful that the GIS team did all this for you!
qgisprocess Package.If there are processing algorithms in QGIS that you want to use in R then this is quite probably the way to go. Its also possible to run algorithms from other toolboxes that are enabled in QGIS from R this way too, such as GRASS or SAGA, although there are R packages that can call these toolboxes without needing QGIS. For large data sets, the necessary round-trip to disk and back if you have the data in R might be limiting.