Positioning agent randomly within GIS space

21 views Asked by At

I am looking to randomly position a fixed number of 'People' agents into my GIS space with regions. I currently have a table with a column for region and have identically named GIS regions in my GIS map. Each 'Person' has a parameter 'region' which into which I map the value of the 'region' column in my table to. I then need to find some way to set the position of the agent to a random point inside the assigned region.

I have tried:

GISRegion myRegion = main.map.searchFirstRegion(region);
Point pt = myRegion.randomPointInside();
setXYZ( pt.x, pt.y, pt.z ); 

in the "On startup" field for my Person Agent but it seems that main.map.searchFirstRegion(region); does not do a good job of getting the correct region, as agents are distributed in places where there is no region (i.e in the sea): Image

Ideally, I would like to use void setLocation(region) but setLocation takes in a Point or INode variable whereas the 'region' parameter is a string. Is there a way to search the list of regions by name for the matching region and return that region? Thanks!

1

There are 1 answers

0
Benjamin On

Likely some issue with initialization order that you are missing.

Add an event into your agent type, make it trigger 0.1 sec after model start and execute your code (applying proper links back to main where needed).

If that does not work, do some tracelns of the code. Does it recognize everything?