AnyLogic
Expand
Font size

Placing agents in GIS space

In agent based models, GIS maps are often used as environment spaces. The environment type for such models is then a GIS space. A GIS space environment type enables you to place agents in a geospatial environment defined by a GIS map. With the GIS space type, you can also set and retrieve an agent’s current location, to move the agent with a specified speed from one location to another, execute an action when the agent arrives at a location, animate an agent at its location (no matter whether it is initially static or moving), establish connections among agents based on their locations, and perform other useful services.

The following video shows how to read agents’ addresses and coordinates from the database and locate agents in the given points on the GIS map:

Placing agents using search results

Using the search menu of the GIS Map shape, you can easily place an agent at a desired location on a GIS map. To do this, you first need to find a desired location, then you assign an agent to the location.

To create and place agents using search

  1. Open a model that contains one or more custom agent types that live in a GIS space.
  2. Double-click the GIS map to enter its edit mode and search for a location on the map where you want to place an agent.
  3. Go to the GIS Search Results view, select the element you need from the list of search results, right-click it, and select the option Create agents at selected elements.
  4. Under this option you will see a list of agent types. Choose the agent type that you would like to create at the selected location on the map.

  5. AnyLogic will automatically create an agent instance and place its animation in the selected location:

  6. You can select several search result elements and apply the action to all of them at once.
The option Create agents at selected elements is only available if there are custom agent types in the model.

To define the initial location for an agent

  1. Let us assume you have some agent living in the GIS space. Select this agent in the graphical editor and go to its Properties view.
  2. Expand the Initial location section,and choose one of the following options from the Place agent(s) list of options:
    • at the agent animation location — [default option] the agent is placed at the place where the agent’s presentation is located in the graphical editor;
    • in the latitude/longitude — the agent is placed in the point defined by its coordinates (using the Latitude and Longitude controls below);
    • in the node — select this option if you want to place agent in a GIS Point or inside a GIS Region. You select the required GIS space markup shape from the Node list below;
    • in the first result of map search — you specify name of the GIS place (e.g. "Paris") in the Location name field below, and the GIS map will search for the place with this name. The agent will be placed in the GIS point that is the first result returned by the GIS map search.

Defining locations in code

With the following functions, you can define an agent’s initial location on a GIS map in your code. These functions should be used only to initialize an agent’s location. They should not be used to move an agent.

There are three ways to define an agent’s initial location using code:

  1. You can put a GIS Point or GIS Region element on the map, and use its node as the agent’s location.
  2. You can place the agent at the location of another agent.
  3. You can define the location’s latitude and longitude.
Function Description
void setLocation(INode node) Puts the agent in the specified location: a GIS point or region.

node — name of the location.
void setLocation(Point point) Puts the agent in the specified GIS point.

point — name of the location.
void setLocation(Agent agent) Puts the agent into the location of another agent.
void setLatLon (double latitude, double longitude) Sets the coordinates of the agent location.

latitude — the latitude coordinate of the location measured in degrees: (-90 ... (South) ... 0 ... (North) ... 90).
longitude — the longitude coordinate of the location measured in degrees: (-180 ... (West) ... 0 ... (East) ... 180).
How can we improve this article?