GeoAgent and AgentCreator classes#

class GeoAgent(model, geometry, crs)[source]#

Base class for a geo model agent.

Create a new agent.

Parameters:
  • model – The model the agent is in.

  • geometry – A Shapely object representing the geometry of the agent.

  • crs – The coordinate reference system of the geometry.

property total_bounds: ndarray | None#

Return the bounds of the object in [min_x, min_y, max_x, max_y] format.

Returns:

The bounds of the object in [min_x, min_y, max_x, max_y] format.

Return type:

np.ndarray | None

to_crs(crs, inplace=False) GeoAgent | None[source]#

Transform the object to a new coordinate reference system.

Parameters:
  • crs – The coordinate reference system to transform to.

  • inplace – Whether to transform the object in place or return a new object. Defaults to False.

Returns:

The transformed object if not inplace.

Return type:

GeoBase | None

get_transformed_geometry(transformer)[source]#

Return the transformed geometry given a transformer.

step()[source]#

Advance one step.

advance() None#
classmethod create_agents(model: Model, n: int, *args, **kwargs) AgentSet[T]#

Create N agents.

Args:

model: the model to which the agents belong args: arguments to pass onto agent instances

each arg is either a single object or a sequence of length n

n: the number of agents to create kwargs: keyword arguments to pass onto agent instances

each keyword arg is either a single object or a sequence of length n

Returns:

AgentSet containing the agents created.

property crs: CRS | None#

Return the coordinate reference system of the object.

classmethod from_dataframe(model: Model, df: pd.DataFrame, **kwargs) AgentSet[T]#

Create agents from a pandas DataFrame.

Each row of the DataFrame represents one agent. The DataFrame columns are mapped to the agent’s constructor as keyword arguments. Additional keyword arguments (**kwargs) can be used to set constant attributes for all agents.

Args:

model: The model instance. df: The pandas DataFrame. Each row represents an agent. **kwargs: Constant values to pass to every agent’s constructor.

Only non-sequence data is allowed in kwargs to avoid ambiguity with DataFrame columns.

Returns:

AgentSet containing the agents created.

Note:

If you need to pass variable data or sequences, add them as columns to the DataFrame before calling this method.

property random: Random#

Return a seeded stdlib rng.

remove() None#

Remove and delete the agent from the model.

Notes:

If you need to do additional cleanup when removing an agent by for example removing it from a space, consider extending this method in your own agent class.

property rng: Generator#

Return a seeded np.random rng.

property scenario#

Return the scenario associated with the model.

class AgentCreator(agent_class, model=None, crs=None, agent_kwargs=None)[source]#

Create GeoAgents from files, GeoDataFrames, GeoJSON or Shapely objects.

Define the agent_class and required agent_kwargs.

Parameters:
  • agent_class – The class of the agent to create.

  • model – The model to create the agent in.

  • crs – The coordinate reference system of the agent. Default to None, and the crs from the file/GeoDataFrame/GeoJSON will be used. Otherwise, geometries are converted into this crs automatically.

  • agent_kwargs – Keyword arguments to pass to the agent_class.

property crs#

Return the coordinate reference system of the GeoAgents.

create_agent(geometry)[source]#

Create a single agent from a geometry. Shape must be a valid Shapely object.

Parameters:

geometry – The geometry of the agent.

Returns:

The created agent.

Return type:

self.agent_class

from_GeoDataFrame(gdf, set_attributes=True)[source]#

Create a list of agents from a GeoDataFrame.

Parameters:
  • gdf – The GeoDataFrame to create agents from.

  • set_attributes – Set agent attributes from GeoDataFrame columns. Default True.

from_file(filename, set_attributes=True)[source]#

Create agents from vector data files (e.g. Shapefiles).

Parameters:
  • filename – The vector data file to create agents from.

  • set_attributes – Set agent attributes from GeoDataFrame columns. Default True.

from_GeoJSON(GeoJSON, set_attributes=True)[source]#

Create agents from a GeoJSON object or string. CRS is set to epsg:4326.

Parameters:
  • GeoJSON – The GeoJSON object or string to create agents from.

  • set_attributes – Set agent attributes from GeoDataFrame columns. Default True.