How to embed netlogo model in a webpage ?

406 views
Skip to first unread message

vidus...@gmail.com

unread,
Oct 18, 2021, 10:14:46 PM10/18/21
to netlogo-users
Hi All 

My NetLogo model is a part of one large project that aims to develop a decision-support tool combining various projects. My model uses a number of GIS data for initialization and model run. I have had a look at NetLogo web but according to the FAQs, GIS extension is not supported. My knowledge in coding etc is very basic.

Can anyone guide me for a way/help-resources to embed my model within an online tool? Or is there anything that can convert NetLogo code to some other language. 

I know my question is very vague at this stage but I would really appreciate if anyone can shed some light on this topic.

Thank you

Kind Regards

Vidushi


Jeremy Baker

unread,
Oct 22, 2021, 2:41:24 PM10/22/21
to vidus...@gmail.com, netlogo-users
Hey Vidushi,

You are correct that there is no support for the GIS extension in NetLogo Web yet.  There are a couple workarounds that could still let your model run in NetLogo Web, but they won't work in all cases and there is a good bit of manual effort involved.  Basically we can try to copy your GIS data directly into the NetLogo model's code so that it doesn't depend on the GIS extension to read it anymore.

If your model is using the GIS extension to load a dataset and use it to create turtles and patches, then the workaround might be helpful.  If you're using the GIS extension during your model run, such as testing for turtles being inside shapes or generating new turtles inside shapes, then this technique would not work.  It also might not work if you have a very large amount of data or if you change your GIS data source a lot.

The idea is that you load your data, create your turtles and/or patches, then take a snapshot of that NetLogo-specific data that you copy/paste back into the model code directly.  You then swap your GIS-based setup for this hard-coded setup that's based on the same data.  Then you can remove the GIS extension altogether and can use the model on NetLogo Web.

If you look at the GIS General Examples model that comes with NetLogo 6.2.1, it has a `make-city-turtles` method like this (slightly modified so you see where the dataset comes from):

```
to make-city-turtles
  ask cities [ die ]
  let cities-dataset gis:load-dataset "data/cities.shp"
  gis:create-turtles-from-points cities-dataset cities [
    set color scale-color red population 5000000 1000
    set shape "circle"
  ]
end
```

So if I want to convert this imported GIS data into a list I can copy/paste into the model I'd do something like the below in the command center:

```
show [(list xcor ycor color)] of cities
```

That spits out a very big string which is the list of all the city coordinates and colors (populations).  So I can copy/paste that into a new procedure:

```
to make-city-turtles-from-list
  clear-all
  let city-data [[13.44680150349935 14.163708580864801 19.631926385277055]...] ; big long string of list data for 606 cities
  foreach data [ [c] ->
    create-turtles 1 [
      set shape "circle"
      set xcor (item 0 c)
      set ycor (item 1 c)
      set color (item 2 c)
    ]
  ]
end
```

And now I can use `make-city-turtles-from-list` instead of the GIS-based version in my model.

This model only contains 606 city elements with 3 data points, so that's not too bad.  If you have thousands and thousands of turtles or patches whose data you need to capture, then you might have to split the list literal up over several lines to keep NetLogo happy.  

If this does sound useful for your model and you decide to give it a try, just let me know if you have any questions and I can elaborate further.

-Jeremy



From: netlog...@googlegroups.com <netlog...@googlegroups.com> on behalf of vidus...@gmail.com <vidus...@gmail.com>
Sent: Monday, October 18, 2021 9:14 PM
To: netlogo-users <netlog...@googlegroups.com>
Subject: [netlogo-users] How to embed netlogo model in a webpage ?
 
--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/1cf2ce3b-92aa-48c7-85bd-51fb20a7dfaen%40googlegroups.com.

vidus...@gmail.com

unread,
Oct 25, 2021, 1:48:51 AM10/25/21
to netlogo-users
Hi Jeremy 

Thank you for your suggestion. 

My model uses study_area boundary  (.shp) to create a pach-set of study area where all the following data set are used:

1) agents initialized from a random patch within their residential_postcode boundary (.shp)
2) Two different resource scenarios e.g. baseline and future each 
3) Patches read resource variables from 24 rasters (i.e. two sets of twelve rasters each representing a monthly value for two vaiables) for each scenario. There are total 48 input rasters (.asc) , 24 are used at a time based on the selceted scenario. 

Do you think this is okay for the option that you have suggested ? Once I get it working in NetLogo web how can it be added to any website / tool ? 

Kind Regards

Vidushi

John Chen

unread,
Oct 25, 2021, 10:16:33 AM10/25/21
to vidus...@gmail.com, netlogo-users
Once you get it to work, you could use an iframe to embed it. 

vidus...@gmail.com <vidus...@gmail.com> 于2021年10月25日周一 上午12:48写道:
Reply all
Reply to author
Forward
0 new messages