Random GIS Point on the Anylogic map

Viewed 53

The Anylogic map has a GIS Regions consists more than one area separated from each other. For example:

enter image description here

If I try to generate a random GIS Points in this GIS Region with next method:

gisPoint = gisRegion.randomPointInside();

the Anylogic generate them in only one area of GIS Region (I don't understand how it choose a specific area)! How can i solve this problem?

Thanks for your help!

2 Answers

So then you automatically have a multiregion right? If you create regions consisting of more than one region you should also have a multiregion visible in the projecttree.

You could then still use the same logic as described above, code would then be:

GISRegion region = Nederland.randomRegionInside();
Point gisPoint = region.randomPointInside();

myAgents(0).setLocation(gisPoint);

enter image description here

Ok, so in case you're using the method map.searchFirstRegion(municipalityName) it obviously doesnt work as you intend because there are still 2 regions and it only selects the first one. If you, for example do the same with the US, it keeps on placing the agent on just one of the many US regions, a small island. So the method you're using is not the correct one.

Since this is a region consisting of 2 regions, this is a multiregion. So instead of looking for the first region, you should look for the first multiregion. For this you could use code like below:

GISMultiRegion multiregion =  map.searchFirstMultiRegion("United States of America");
GISRegion region = multiregion.randomRegionInside();
Point gisPoint = region.randomPointInside();
myAgents(0).setLocation(gisPoint);

Looks like gisRegion is just one of the regions? If it is, it makes sense only a random point is chosen inside one region.

To solve this, you can try something like this(just figured it out myself):

First create a multiregion and add both regions to it. Then choose a random region. Then for this random region, choose a random point inside this region.

GISMultiRegion multiregion = new GISMultiRegion();
multiregion.add(gisRegion);
multiregion.add(gisRegion1);

GISRegion region = multiregion.randomRegionInside();
Point gisPoint = region.randomPointInside();

myAgents(0).setLocation(gisPoint);
Related