Pages

Friday, October 30, 2015

Tutorial on Using and Exporting GIS Vector Dataset in Netlogo

Hi, this is a tutorial on how to import and export Vector dataset in Netlogo. It could be helpful when you want to study a specific area, and you have the data in ArcGIS, for example a shapefile. In this post, you will learn how to import the data into Netlogo and run simulations with it, as well as how to export the data back to ArcGIS for further analysis. Note that this tutorial is for Vector data, if you are interested in using Raster dataset in Netlogo, please check my post on the Urban Growth Model.

In this post, I will talk about how I developed a Schelling segregation model using the map of Washington DC. The model and data are available here:


And a video showing how it works:



Importing and drawing Vector data

Netlogo has a GIS extension that allows us to read data files from GIS and copy the values to patches or turtles for simulation. I am using the following lines to load the Vector data into Netlogo. Note that by loading the shapefile, you will also load the attributes in the .dbf file and the projection information in the .prj file.

Next, I drew the map on the display. To do that, I am using the following lines. In these lines I go through each vector-feature (each polygon), change the drawing color according to the SOC attribute, and then fill the polygon with the corresponding color. In the last two lines, I use gis:draw to draw the boundary of polygon data using white color.


Copying attributes to patches

In Netlogo, we can not ask a polygon to perform anything. Therefore, in order to study the area, we need to copy the attributes into patches. To do that, I loop through each polygon and copy the color attribute to the patch at its centroid. In this way, I am using one patch to represent one polygon. Mind that you may need to have a larger size of Netlogo map, so that two centroids will not lay on the same patch.

Since this is a segregation model, I have also found the neighbors of all polygons. ArcGIS has a tool called Polygon Neighbors. For each polygon, the tool finds all the polygons that have coincident edges with it, and reports the information in a table. I exported this file to a text file and deleted all the headers and labeling numbers. Then, I use the following lines to ask each patch that represents a polygon to read the file and set neighbors.


Exporting Vector dataset

After running the simulation, how do we export the final map into ArcGIS for further analysis? So far the GIS extension does not allow us to modify or create a vector dataset. My idea is to write the information into a text file, open it in ArcGIS, save it as a .dbf file, and replace the original .dbf file. Here are the codes I used to do that.


The color information is stored in the patches that represent polygons. Therefore, I loop through those patches and ask them to write down their ID and then color. Note that more attributes could be easily included in the table if necessary.

It does take an extra step to use this attribute table in ArcGIS.  Simply open the text file in ArcGIS, save as .dbf, and replace the original one (remember to make a copy).


I wish you find this tutorial helpful!







Wednesday, October 14, 2015

3D Rainfall Model in Netlogo

Hi, recently I have developed a 3D rainfall model using Netlogo. The model shows how Netolog can display elevation in a 3D model, and run simulation based on the elevation. The raindrops are also created in a 3D way for visualization.The map being used here is the Crake Lake. I use the ASCII file obtained from nationalmap.gov.

Here is a video recording the simulation process.



Please find the code here:
https://github.com/YangZhouCSS/Rainfall_Model_3D

See this post for the 2D version of this model:
http://geospatialcss.blogspot.com/2015/10/rainfall-model-of-crater-lake-national.html

I would like to briefly introduce how I created this model in Netlogo.

The method I used to visualize the elevation in a 3D way is inspired by Netlogo's Hill Climbing 3D. Netlogo does not have a built-in function to create a surface based on elevation data. What I did is that I asked patches with pzcor = 0 to read the elevation data, and each create a turtle at zcor equal to the elevation. Then, I use  the comment "create-links-with turtles-on neighbors" to create links between the turtles created in the last step, then I hide the turtles. In this way, a "surface" will be created, at least, it looks like a surface for visualization purpose.

The way I created the raindrops falling is inspired by Netlogo's Raindrops 3D. I created turtles representing raindrops at the top of the world, and ask them to face down and forward 2 steps in a tick, until they reach the surface.

To move the raindrops on the surface, it is more tricky. Patches at the base (those with pzcor = 0) have a variable called [top], which measures the elevation plus water height here. The raindrops read the variable [top] and flow to patches with lowest top.

I hope you enjoy this post!


Thursday, October 1, 2015

Rainfall and Erosion Model of the Crater Lake National Park using Netlogo

I have created this model of Rainfall and water runoff. It simulates the runoff of the rain and its erosion. This model is inspired by the Grand Canyon Model.

You can use the export function to export the elevation map after erosion to a .asc file for further studies in ArcGIS.

The map being used is the Crater Lake National Park in Oregon. See below for an elevation map.



Rain drops are created randomly on the map based on the rain rate parameter. Rain drops will run to the neighboring patch with the lowest elevation. Besides, if there are already water in a patch, the height of water will also be added to its elevation, when raindrops are selecting the patch to run to. If a raindrop can not find a neighboring patch with lower elevation, it will stay where it is and become water. When raindrops run to the edge of the map, they are removed from this model.

See below for a video recording a simulation process:


This is an image showing the result after 700 ticks.


This is a map showing the amount of water in scaled color, where darker color implies higher volume of water.



See below a video for the verification of the model:


Please visit the following link for the code.
https://github.com/YangZhouCSS/Rainfall_Model