21 thoughts on “The NetLogo GIS extension: a tutorial

  1. Pingback: NetLogo post summary | Scientific Gems

  2. Pingback: Revisiting Artificial Anasazi: a NetLogo tutorial (part 1) | Scientific Gems

  3. Thank you for your information. i am trying to make evacuation model by using Letlogo. Before seeing your article, I just used ‘import-pcolor’. And I realize that it must need GIS data to make better agent-based model.

      • I am working on an evacuation model for a building. I used shape file and vectordataset for setting up the environment. What is your suggestion for generating the environment?
        Also, I got a problem with the gis:apply coverage primitive. It gives a runtime error. “Extension exception: not a vectordataset ”
        Do you know any solution for this?
        I can send you both shap file and the netlogo code, if you need.

      • The error “Extension exception: not a vectordataset” may mean that you have a raster file rather than a vector file. As to generating the environment, it depends on your goals for the simulation.

    • 510,000,000 sq km is the surface area of the planet, and N is the number of patches. Of course, this has substantial distortion due to the map projection, as noted in the blog post.

  4. I have lat/long data to map the lower 48 states of the U.S. Plus lat/long for selected cities. However, I wanted to add Congressional Districts or maybe zip code areas to the map, so I am trying the GIS extension to Netlogo. The maps look much better. However, when I try to put the cities on the vector map, they are off. Not sure how to coordinate the two. The Netlogo world sets 0,0 in the lower left corner, and I convert the city lat/long to Netlogo coordinates. Also do this for the non-GIS version of the maps, and that looks okay. But when I use the GIS map, it’s not fitting into the Netlogo world so that the lat/long data matches. Any way to fix this? These cities are not going to be in a GIS database – or at least many of them won’t. Thanks for any advice you have.

    • Well, first, there’s an option when you right-click edit on the Netlogo world to set the origin 0,0 (I usually have it in the centre).

      Second, the Netlogo coordinates specify patch centres. If you have the origin in the lower left, x actually runs from -0.5 to max-pxcor + 0.5, and y runs from -0.5 to max-pycor + 0.5 (although only the range 0 to max-pxcor and 0 to max-pycor are legal turtle positions). You need to do the conversion correctly.

      Third, there may still be a bug in the Netlogo GIS extension. I notice that the patches and lines in my example don’t 100% line up. You might need to do some experimentation with the coordinates of geographic features and then compensate for the error. I must confess that I’ve never done anything requiring that level of accuracy.

      • I think your second comment may help – trial-and-error resulted in “correction factors” very close to the min latitude and longitude that is subtraced from each city’s location. These are within 0.5 of the actual boundary lat/long points. Will have to look at this when I’m more awake.

        The CONUS map looks pretty good, though. Cities seem to be where they should be – i.e., not yet under water and in the expected states! Need to check this out for individual states, though.

      • Tony,
        Some more progress, but more questions. I imported the data files I use in Netlogo into QGIS. The cities lined up really nicely. Then I created a shapefile and went back to Netlogo. I can now create a U.S. map with the cities and have a button that turns the cities on and off. So then I added the cities as agents using the same data file that QGIS used. And they are all a little off. And it’s not consistently to one direction – some to the right, some up to the right, some down, etc. So is there a way to create or link an agent to a point from the GIS city? I am just getting into the GIS extension, so I am not familiar with all the options. Or is it possible to retrieve the patch from the GIS city points? That might work, too. Thanks for your help.

      • It’s hard to know what’s wrong without seeing your code. It could still be the kind of coordinate mismatch I described before (especially if the errors go the same way in similar parts of the map). Whatever it is, you could probably reduce the problem by editing the world (right-click and edit) to have more and smaller patches.

        I don’t understand your other questions, precisely, You can certainly use the ordinary patch-here to identify the patch that an agent is on and setxy to reset an agent’s position.

  5. Turns out that I can import the cities file into QGIS and create a shapefile. Then back in Netlogo the cities and background maps can be merged. The code example in the Models library that you mention in the tutorial shows how to do that and create agents. So all is well! Thanks for your help.

  6. Hello,
    I’m trying to include 5 rasters in my model, all the rasters are from the same region, but when I apply more than 1 occurs the following extension error.
    Extension exception: Dimensions (width=334991 height=334992) are too large
    error while observer running GIS:APPLY-RASTER
    called by procedure DISPLAY-CLASES-IN-PATCHES
    called by Button ‘display-clases-in-patches’
    What can I do? I think is something related with
    gis:set-world-envelope (gis:envelope-union-of (gis:envelope-of apt-dataset) (gis:envelope-of clases-dataset))
    Is something wrong?

    • You should probably contact the NetLogo people themselves, but I’m guessing your rasters are just much to large (if the dimensions are really width=334991 height=334992). Alternatively, if the rasters are from different areas, NetLogo is being forced to build such a large raster internally to hold the five pieces.

      Can you combine them all the rasters into one using GIS software before loading them into NetLogo? It sounds like you may need to downsample the rasters to fit your patch grid as well.

      • Hi!
        Thank you very much, your info was very useful.
        The problem was in the projections of the rasters and, as you said, NetLogo was being forced to build a large raster.

  7. Hi!

    I loaded a shapefile of rivers into Netlogo and I want to determine for every patch the distance to the closest river. I thought I should first tell a patch whether it belongs to a river, but I can’t quite figure that out using gis:apply-coverage. One reason is that I don’t know how to access the attributes from a shapefile in Netlogo. Do you have some suggestions on how to do this?

    • The latest version of the GIS extension (see here) has some operators that look like they will do the job. Unfortunately patches can’t interact with a drawing of the rivers. You could, however, use gis:apply-coverage (which copies attributes from a shapefile) if there are attributes properties, or you can use gis:intersects?.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.