0

I am trying to create an agent based model. I have a GIS shapefile for a county that consists of 190 census tracts. I have uploaded the shapefile into AnyLogic and have 190 regions in Main>Presentation>level>map. Now Using first 15 regions (census tracts), I want to create a big region (named as neighborhood). Once I select 15 regions and right-click, it gives me an option to create collection. I saw in AnyLogic help page, about functions for multi-region (r.g.; boolean addAll(Collection regions)). But I don't know where should i write this code.

I really appreciate your help!

I have selected 15 regions and form a collection. But I want a region.

1 Answers1

0

The multiregion only works if you use the search functionality... so what you need to do is to create a variable of type GISMultiRegion initialized with

new GISMultiRegion()

example

Then on Main startup you have to add the regions you want if it's called multi you can do

multi.add(gisRegion1);
multi.add(gisRegion2);

And so on

or you can create a collection of all your regions and do

multi.addAll(collection);
Felipe
  • 8,311
  • 2
  • 15
  • 31
  • Thank you so much @Felipe. I tried to implement your suggestion. Did you mean to create this variable (e.g. multi) on the Main tab? I created multi variable on the Main tab with type & initial value as you said. Then on the Main tab in; On startup: . addAll(). How can I find that newly created region? I want to use that region to place my agents (100 people randomly). If you know the region name, I can use [ Point pt = get_Main().REGION NAME.randomPointInside(); setXYZ( pt.x, pt.y, pt.z );. My ultimate goal is to place 100 people randomly on that combined region. I am new in AnyLogic. – Morshed Dolon Nov 07 '22 at 23:06
  • you can only access the regions through their index such as multi.getRegions().get(0).randomPointInside() where 0 is the index – Felipe Nov 08 '22 at 00:28
  • if you want to use the name something like this would work: findFirst(multi.getRegions(),r->r.getName().equals("region name")).randomPointInside() – Felipe Nov 08 '22 at 00:29
  • I tried: get_Main().multi.getRegions().get(0).randomPointInside(); Got an error says "Index 0 out-of-bounds for length 0". How can I get index? Also, in your second comment, how can I get "region name"? – Morshed Dolon Nov 08 '22 at 15:00
  • because you didn't add any region to the multiregion yet... – Felipe Nov 08 '22 at 18:06
  • Hi @Felipe, I am really sorry for silly questions and appreciate you. Here are steps I went through: (1) uploaded shpefile with 190 regions. (2) collection1 - with 10 regions. (3) variable "multi" and multi.addAll(collection1); in Maintab. (4) Now in Agent tab ('People'), On startup: get_Main().multi.getRegions().get(0).randomPointInside();.||| How can I add regions to multiregion? I though I created a variable "multi" of type GISMultiRegion and it has all regions added. – Morshed Dolon Nov 08 '22 at 19:24
  • the people population is created before the code that is run on main startup , so you need to create the population later... not a silly question – Felipe Nov 08 '22 at 19:25