Creating QGIS Models with Optional Inputs and Conditional Processing

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. ...

#30DaysOfQGIS - Master QGIS in 30 Days

Welcome to #30DaysOfQGIS! We have launched our Advanced QGIS course on YouTube and have designed this challenge to help you master QGIS! Spend 30 minutes each day for the next 30 days to level-up your QGIS skills. This course is the result of my 15+ years of experience using QGIS for large-scale spatial analysis and automating workflows. I am really excited to share this content with you - completely free. The material is full of tips, tricks and challenges that will make your learning journey fun and rewarding! All you have to do is show up everyday and spend half an hour watching the videos and practicing the exercise. Ready for #30DaysOfQGIS? Read on to know the details. ...

Rendering Print Layouts from QGIS Models

When automating GIS workflows, one often needs to automate the creation of cartographic outputs. The QGIS Model Designer allows you to build a workflow by combining multiple Processing algorithms. QGIS now includes several algorithms under the Cartography category that allow you to integrate the map creation process within your model. In this post, we will explore the Export print layout as image (or Export print layout as PDF) algorithm to automate the creation of a fire map. We will build a model that will automatically Download the latest shapefile of active fires from FIRMS. Extract fires intersecting the continental US. Style the layer using a pre-configured QGIS style file. Render a pre-configured Print Layout. Whenever the model is run, it will output a map such as shown below. ...

Understanding Pixel Weights in Zonal Statistics

An important concept in spatial statistics is pixel weights. When calculating pixel statistics with a polygon, partial pixel overlaps are treated differently by different packages and you need to understand this to evaluate the accuracy of your results. Consider the following image. What is the correct answer? ...

Running QGIS Processing Tools on the Command Line with qgis_process

Modern versions of QGIS comes with a handy command-line utility called qgis_process. This allows you to access and run any Processing Tool, Script or Model from the Processing Toolbox on a terminal. This is very useful for automation since it doesn’t require you to open QGIS or manually click buttons. You can run the algorithms in a headless-mode and even schedule them to run them at specific times. This post covers the following topics How to launch qgis_process command on Windows, Mac and Linux. How to find the parameters and values for each algorithm and build your command Example showing how to do a spatial join on the command-line using the Join Attributes by Location algorithm Example showing how to run a model on the command line to automate a complex workflow Want to follow along? You can download the data package containing all the datasets used in this post. Before running each command, make sure to replace the paths in the commands with the paths on your computer. ...

Split Polygons into Equal Parts using QGIS

In this post, I describe how we can use built-in QGIS processing tools to create a workflow to split polygons into equal parts. Using a clever algorithm and Feature Iterator tool in the Processing Framework, we can easily split all features in a given polygon layer into equal parts. This workflow creates irregular polygons. There are many plugins that allow more control and can divide polygons into regularly sized equal sized polygons. See the complete list at the end of the post. The algorithm for splitting any polygon shape into equal parts is described in this post PostGIS Polygon Splitting by Paul Ramsey. We will see how this can be implemented in QGIS. ...

Calculating Weighted Centroids

In this post, I will outline techniques for computing weighted-centroids in both QGIS and Google Earth Engine. For a polygon feature, the centroid is the geometric center. It can also be thought of as the average coordinate of all points within the polygon. There are some uses cases where you may want to compute a weighted-centroid where some parts of the polygon gets higher ‘weight’ than others. The main use-case is to calculate a population-weighted centroid. One can also use Night Lights data as a proxy for urbanized population and calculate a nightlights-weighted centroid. Some applications include: Regional Planning: Locate the population-weighted centroid to know the most accessible location from the region. Network Analysis: For generating demand points in location-allocation analysis, you need to convert demands from regions to points. It preferable to compute populated-weighted centroids for a more accurate analysis. Do check out this twitter-thread by Raj Bhagat P for more discussion on weighted centroids. Different Weighted Centroids for the State of Karnataka, India (2015) ...

QGIS for Urban and Regional Planning

I recently taught a 1-month long course on GIS Applications in Urban and Regional Planning. We explored how GIS can be applied to solve problems in 6 different thematic areas. In this post, I will outline different applications and show concrete examples of using open-datasets and open-source GIS software QGIS. Update! The full course material - including data packages and PDF handouts - is now available for free download. Download [qgis_urban_planning.zip] containing detailed step-by-step instructions and datasets. You can also access updated versions of some tutorials at qgistutorials.com. Here are the 6 thematic areas Land Use Planning and Management Crime Mapping and Analysis Solid Waste Management Urban Infrastructure and Utilities Urban Transportation Spatial Planning ...

Spatial Homogeneity Testing of Raingauge Data with Advanced QGIS Expressions

Rainfall is arguably the most frequently measured hydro-meteorological variable. It is a required input for many hydrological applications like runoff computations, flood forecasting as well as engineering design of structures. However, rainfall data in its raw form contain many gaps and inconsistent values. Therefore it is important to do rigorous validation of rain-gauge observation before incorporating them into analysis. World Bank’s National Hydrology Project (NHP) prescribes a set of primary and secondary validation methods in theManual of Rainfall Data Validation. Of particular interest to me are the spatial methods aimed to identify suspect values by comparison with neighboring stations. This spatial homogeneity test requires complex spatial and statistical data processing that can be quite challenging. I got an opportunity to work on a project that required automating the entire process of identifying and testing suspect stations. I ended up implementing it in QGIS using just Expressions and Processing Modeler. The whole solution required no custom code and was easily usable by an analyst in the QGIS environment. In this post, I will explain the details of the test and show you how you can use similar techniques for your own analysis. This workflow was presented as a live session on QGIS Open Day. You can watch the recording to understand the concepts and implementation. ...

Fixing Rasters with Missing Data using QGIS, GDAL and Python

When working with raster data, you may sometimes need to deal with data gaps. These could be the result of sensor malfunction, processing errors or data corruption. Below is an example of data gap (i.e. no data values) in aerial imagery. Source Image: © Commission for Lands (COLA) ; Revolutionary Government of Zanzibar (RGoZ), Downloaded from OpenAerialMap. (Note: The data gap is simulated using a python script and is not part of the original dataset) ...

Calculating Shared Border Lengths Between Polygons

In a previous post, I showed how to use the aggregate function to find neighbor polygons using QGIS. Using aggregate functions on the same layer allows us to easily do geoprocessing operations between features of a layer. This is very useful in many analysis that would typically require writing custom python scripts. Here I demonstrate another powerful function array_foreach that allows one to iterate over other features in QGIS expressions - enabling even more powerful analysis by writing just a single expression. ...

Generating Random Points with a Specific Distribution

Generating pseudo-random data is important for many aspects of research work. QGIS provides for many methods of generating random points to facilitate this. Recently, I ran into a problem where I wanted to generate random points inside a polygon - but I wanted the random points to have a certain distribution. I wanted to generate a dataset showing employee home locations for a company. Given a city boundary and the location of office, I wanted to have a point layer that showed where the employees lived. A simple ‘Random points within Polygon’ algorithm would not work here, since the distribution of points would not be uniform within the city. ...

Fuzzy Table Joins in QGIS

Table Joins are a way to join 2 separate layers based on a common attribute value. QGIS has a Join Attributes By Field Value algorithm that allows you to perform table joins. A limitation of this algorithm is that the field values must match exactly. If the values differ slightly - the join will fail. There are many times where you are trying to join 2 layers from different sources and they contain values which are similar but may not match exactly. Fortunately QGIS now has built-in fuzzy string matching functions that can be used - along with Aggregatefunction - to do table join based on fuzzy matches. ...

Find Neighbor Polygons using Summary Aggregate Function in QGIS

Read my previous posts Summary Aggregate and Spatial Filters and Advanced Aggregate Expressions to Automate QA to learn more about the powerful aggregate function. The aggregate function in QGIS was designed to work with 2 separate input vector layers, but we can also make it work with a single layer. Essentially performing spatial queries for features within the layer. The following video explains the workflow. ...

Advanced Aggregate Expressions to Automate QA in QGIS

This post is the continuation of Summary Aggregate and Spatial Filters in QGIS. I have been exploring aggregate functions more and have found interesting ways to automate tasks in QGIS. One such example is helping automatically keeping track of feature edits to help with Quality Assurance (QA). ...

Summary Aggregate and Spatial Filters in QGIS

QGIS expression engine has a powerful a summary aggregate function that can do spatial joins on the fly. This enables some very interesting uses. ...

Creating Animated Flight Lines in QGIS

You may have seen a map where source and destination points are connected via curved lines. It is possible to create such a map in QGIS with a simple trick - using custom projections and densification of lines. I will outline the steps to create such a map. ...