Boids in QGIS part 7:
Implementing an agent-based model in QGIS

In parts 1—6 of this series we worked on implementing the famous boids model in Python and ended up with a pair of scripts that output a CSV file of boid locations which we can then import into QGIS. What if I told you there was a better way? QGIS plugins can be developed in Python, which is mostly why we are using one of my least-preferred languages here, and in this section we will set up a basic implementation of our earlier model to be run from QGIS and output our results as a memory layer directly into our map. We’ll follow Ujaval Gandhi’s excellent tutorial on setting up a Python plugin for QGIS using the plugin builder (GeoApt LLC).

Continue reading “Boids in QGIS part 7:Implementing an agent-based model in QGIS”

Boids in QGIS part 6:
Enforcing speed limits and study area constraints

In my previous post we got our boids implementation to finally follow all of the boids behavioural rules. We still have the problem that they are capable of unlimited acceleration and nearly infinite speed. This is not physically realistic, however, as most fish cannot achieve relativistic velocities and none that we know of can exceed the speed of light. There are also reasonable physical constraints related to metabolism and hydrodynamics and the like that limit how fast they can accelerate. We’ll also tackle another elephant in the room here and begin to talk about enforcing study area boundaries. This is part 6 of my series on implementing boids in QGIS. For part 5 click here, or for part 7 click here. To go to the table of contents, click here.

Continue reading “Boids in QGIS part 6: Enforcing speed limits and study area constraints”

Boids in QGIS part 5:
Putting it together

In our previous exercise we covered the mathematics and code behind implementing each of the three primary boid behaviours. Our model still doesn’t do anything though! In this exercise we will add a function to call the behaviours, weight their importance, and calculate a new acceleration vector. We’ll also (finally) add some constraints on the speed and acceleration of our boids. This is part 5 of my series on implementing boids in QGIS. For the table of contents, click here. For part 4 click here, or for part 6 click here.

Continue reading “Boids in QGIS part 5:Putting it together”

Boids in QGIS part 4:
Primary behaviours

In our last exercise we established how to initialize our model and get the fish to move. A single direction forever is not particularly interesting, however. We need to give our boids some behaviours. In Reynolds’s original description of the model these include only alignment, cohesion, and avoidance. We’ll accomplish these behaviours by computing the acceleration necessary to achieve them and then adding the resulting accelerations together to calculate a new acceleration. This is part 4 of my series on implementing Boids in QGIS. For the table of contents click here. For part 3 click here, for part 5 click here.

Continue reading “Boids in QGIS part 4:Primary behaviours”

Boids in QGIS part 3:
Layout and constraints

So we’ve decided on implementing boids in QGIS. We’ll need to establish how our boids are going to function and what the physical constraints of our boids are going to be. At minimum we need a Python class describing our boid objects, how to update them, and how to trigger their behaviours. We’ll also add some reasonable physical constraints here. This is part 3 of my series on implementing boids in QGIS. For part 1 and the table of contents, click here. For part 2 click here, for part 4 click here.

Continue reading “Boids in QGIS part 3:Layout and constraints”

Boids in QGIS part 2:
A note on testing

An agent-based model typically consists of two components: an object describing our agent, and a control script that is responsible for running and tracking the system. If you want to think ecologically, this is a separation between our individual animals and their environment. Since we are ultimately going to use this agent in a QGIS plugin, the control script will be built into the QGIS plugin and I will cover that aspect later. For quick testing you can use this script. It creates a list of agents, and calls each of their updates and behaviour functions in a loop. The output is a csv file that you can import into QGIS to see the results as well as a timestamp that is readable by the QGIS TimeManager plugin (Graser et al.) This is part 2 of the series. Click here for part 1, or here for part 3.

Continue reading “Boids in QGIS part 2:A note on testing”

Boids in QGIS part 1: Introduction and contents

The natural world is full of complex group behaviours. Birds flock, fish school, and ants march in lines. Even plants, some microbes, and plankton exhibit group behaviours. These behaviours can usually be modeled, and are often relevant to the ecological interactions and spatial distribution of the species that exhibit them. In this short series, we’ll implement Boids, a common agent-based model of schooling behaviour in fish and birds in QGIS, a popular open source GIS platform. This is part 1 of the series, the introduction and contents post. Click here for part 2.

You can also check out the code for this on my github.

Continue reading “Boids in QGIS part 1: Introduction and contents”