Masthead

Lab: Spatially-Explicit Agent Based Model Using NetLogo GIS Extensions

In this lab you will use the GIS extensions to NetLogo to create a spatially-explicit model in an existing landscape.

GIS Extensions

The GIS extension for NetLogo allows you to load and display GIS information in ASCII Grid files and shapefiles. You can also access the data.

Loading and Displaying Data

The code below load a shapefile on setup and then display it when the "display-countries" button is pressed.

extensions [ gis ]
globals [ countries-dataset ]

to setup
  set countries-dataset gis:load-dataset "C:/ProjectsModeling/NetLogo/cntyoutl/CNTYOUTL.SHP"
end

to display-countries
  gis:set-drawing-color white
  gis:draw countries-dataset 1
end
    

The code below will load three raster files and then display each one based on a different button press.

extensions [ gis ]

globals [ elevation slope aspect ]

to setup
  clear-all
  set elevation gis:load-dataset "data/local-elevation.asc"
  gis:set-world-envelope gis:envelope-of elevation
end 

Note that the loading of shapefiles and raster files is similar but the command "draw" is used to render vector data (shapefiles) and "paint" is used to render rasters into the view.

Accessing Values

I have not explored accessing vector data within NetLogo but the code below will access the raster values where "x y" is the horizontal and vertical location of the desired pixel. "raster" is the name of the variable containing the raster and "gx" is the variable to be set to the pixel value.

let gx gis:raster-value raster x y

You can also get values based on a turtles position as in the code below:

let h gis:raster-sample raster self 

Note that here we are using "let" to create the variables instead of "set" for variables that are already defined.

Hints

Filtering "NaN" values. NaN stands for "not a number". This occurs with values generated on computers, for instance when zero is divided by zero (0/0). You can detect these in NetLogo with:

if ((gx <= 0) or (gx >= 0)) and ((gy <= 0) or (gy >= 0)) ;; if this is true, the values gx and gy are valid 

The GIS Examples

There are only a couple of examples available for the GIS extension. In NetLogo, to to "Models Library -> Code Examples -> GIS". The "GIS General Examples" shows how to load and render various types of GIS data into the NetLogo interface. It does not access the data. The "GIS Gradient Example" shows how to access the values within rasters, create new rasters, and move turtles based on raster values. This is a rather interesting example but I think creating rasters can be better done in a GIS application. Take a look at each of these examples and I recommend saving your own copy of them with comments.

Designing The Model

For this task, you'll want to select an area that you have data for and than can be represented in a relatively small number of pixels (i.e. about 200x200). Otherwise, you'll spend too much time working on performance to complete the model in the time allotted.

You'll also want to select a relatively simple model such as predator-prey, migration, or moving between roosting and feeding locations. Do not try to put too many behaviors together in one model.

Building The Model

It may be best to start with one of the examples and just replace some of the GIS data with your own. Then, I recommend creating some turtles and moving them about based on the raster data beneath them. One example would be to use the raster data to represent the type and/or amount of forage and have your turtles interact with it as the sheep did in the Wolf-Sheep model.

Here are some examples of me working with the GIS Extension:

Turn-In

Turn in a NetLogo script with the associated data in the same folder. I prefer that you make the code execute from the "C:\Temp" folder to make grading easier. Remember to fully document the script.

 

© Copyright 2018 HSU - All rights reserved.