Weekend project:
Boids implementation in QGIS

I had a couple of hours of spare time over the weekend, so I decided to start work on implementing a simple (and well-studied!) ABM in Python for use as a QGIS plugin. I put together a quick series of notes on how to build it, which can be found here. I’ve uploaded the complete scripts to my github page. The project so far implements all of the traditional boids behaviours, as described by Reynolds (1987).

Things it seems to do well:

  • All three boids behaviours work
  • Behavioural weighting allows fine tuning of the three behaviours for species and context specificity
  • Placement of agents at arbitrary initial positions works really well
  • Steering away from the study area boundaries looks clumsy but is very effective

Things that need improvement:

  • The study area limits are currently a rectangle, this should be updated to interact with a shapefile layer containing shorelines, etc.
  • Currently the perception distance is a perfect circle with a fixed radius around the centre of the agent, so is avoidance distance. These might need to be revised to a more complicated system to better represent directional vision, etc.
  • All agents always enact their behaviours in the same order each time.
  • Presently the model is implemented in two dimensions only, this is for ease of testing and can be fixed in the future.

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”

Georeferencing Humminbird sonar files

Commercially available side-scanning sonar units sold for anglers are a good, low-cost option for substrate classification in rivers and lakes. The units are small, portable, and very inexpensive. Unfortunately retrieving data from these units often involves replaying data on the unit itself or capturing screen shots which are typically distorted representations of the bottom. Overlaying the data on a map could be very helpful. I put together a quick C++ project to turn Humminbird 698ci side images into georeferenced TIFF files for a river surveying project. The focus is on legibility and some spatial accuracy is sacrificed for image clarity. The project as well as a fuller writeup of how to use it can be found on github here: sonar gridder.

Check out my other projects on github too while you are at it!