In a recent post I showed how to obtain minimum edge to edge distances using PostGIS. https://duncanjg.wordpress.com/2012/09/23/edge-to-edge-distance-using-postgis/
The reason for running an analysis that extracts edge to edge distances is to use them when setting up a network of connected nodes for modelling processes on a landscape. Such a network forms the conceptual (and operational) basis of a great number of metapopulation models. The network could also be used when setting up disaggregated agent based models.
However, before moving towards the use of edge to edge based distances I will show a simpler setup in netlogo that uses the absolute distances between polygon centroids. This is unrealistic in many situations, for all the reasons previously discussed, but it can be useful if each polygon is relatively small in relation to separation distance.
The example also shows some of the (good and bad) features of the netlogo gis extension that need to be considered when importing vector layers.
The setup procedure for the model loads the centroids from the polygons shown in the previous post into netlogo. The gis extension has the capability to find the centroids itself, but it is probably better to extract them in GIS first in order to keep everything clear.
The make-network command (see annotated code below) then joins the points at the given separation distance as shown on the slider in meters.
The draw-polys adds the polygon layer from which the centroids were derived to the display
So, here is the netlogo model and the data files for download. Look for the line where the path is set and change it to the place that you have stored the data in order to run it after unzipping.
The annotated code.
extensions [ gis ];;This makes the gis extension available. ;; It is provided by default in netlogo 5 ;; ;;The netlogo lists into which the gis layers are loaded have to be defined as ;; globals. So we have "wood" for the polygons and centroids ;; There is also a global scale factor that is used to translate meters into ;; Netlogo units. It took me a while to see why this was necessary, as I assumed ;; it was all taken care of in the "setup-gis-world" function ;;In fact it is very important to get this right when loading rasters and setting patch variables from them. globals [path wood centroids scale_factor] ;; The global variables include the names that the GIS layers will have when imported ;; The scale_factor is the ratio between the width of a netlogo patch and the unit of ;; measurement (m) in the GIS layer. breed [habitats habitat] ;; The nodes are habitats. They are given a breed name habitats-own [gid area perimeter occupied] ;;The properties of the habitats could be estended in a more detailed model links-own [dist] ;; Links may own the property of distance, if measured. In a model with edge-edge distance this ;; will become very important. to setup clear-all set scale_factor 100 ;; Do not forget the scale fator! 1 km will be 10 units in the model. set path "/home/duncan/Dropbox/Public/netlogo_models/NewForest/" ;; Set this line to the folder where the data lies. set wood gis:load-dataset (word path "NFAnWood.shp") ;; Import the polygons set centroids gis:load-dataset (word path "NFAnWood_Centroids.shp") ;;Import the centroids setup-gis-world gis:envelope-of wood 2 ;; The line above is vital. Check the setup-world-function below for more details. gis:draw centroids 2 ;; This does what it says. The centroids are now drawn on the interface. But they may be ;; overwritten once they have been converted into "turtles" of the habitat breed using the ;; code below. ;; Notice that we need to cycle through the feature list. Each member of this list ;; coincides with a row in the vector layer attributes table. foreach gis:feature-list-of centroids [ ;; In this case there should only be one vertex, but use the code in the conventional ;; Gis extension example for safety. let location gis:location-of (first (first (gis:vertex-lists-of ?))) ;; Now simply place a habitat turtle at each position and set all its attributes- ;; Some of these are read from the vector layer. create-habitats 1 [ set shape "circle" set color green set xcor item 0 location set ycor item 1 location set gid gis:property-value ? "gid" set area gis:property-value ? "area" set size 1 set perimeter gis:property-value ? "perimeter" ]] ;; All set up and ready to form links. BUT DO READ THE COMMENTS FOR THE SETUP-GIS_WORLD FUNCTION!! end to make-network clear-links ask habitats [create-links-with other habitats in-radius (sep_dist / scale_factor) ] end to setup-gis-world [bbox patchsize] ;; The bounding box is read from the gis layer that is passed to this function. See the call in "setup". let gis-width item 1 bbox - item 0 bbox ;; Find the width of the box in GIS units (probably meters) let gis-height item 3 bbox - item 2 bbox ;; Find the height in GIS units. resize-world 0 gis-width / scale_factor 0 gis-height / scale_factor ;; This is VITAL: The underlying coordinate system is resized. This is not explicit in the examples provided. ;; It is necessary to ensure that when a call is made to a function such as "in-radius" there is a clear ;; reltionship between the units used by netlogo and the GIS units. In this case the scale factor of 100 results in ;; a corrspondence of 1 unit in netlogo space to 100 m in gis space. This is not obvious in examples ;; which do not mix the two. It is particularly important when rasters are imported, as this is all related to resolution ;; and grain size. set-patch-size patchsize ;; The patch size could be derived automatically, but here it is set in the function call. ;; Again be careful here. This controls the grain size of the diplay. ask patches [set pcolor white] gis:set-world-envelope bbox end to draw-polys gis:set-drawing-color green gis:draw wood 2 end