GeoAgent and AgentCreator classes#
- class GeoAgent(unique_id, model, geometry, crs)[source]#
Base class for a geo model agent.
Create a new agent.
- Parameters:
unique_id – Unique ID for the agent.
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
- 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. Must NOT include unique_id.
- property crs#
Return the coordinate reference system of the GeoAgents.
- create_agent(geometry, unique_id)[source]#
Create a single agent from a geometry and a unique_id. Shape must be a valid Shapely object.
- Parameters:
geometry – The geometry of the agent.
unique_id – The unique_id of the agent.
- Returns:
The created agent.
- Return type:
self.agent_class
- from_GeoDataFrame(gdf, unique_id='index', set_attributes=True)[source]#
Create a list of agents from a GeoDataFrame.
- Parameters:
gdf – The GeoDataFrame to create agents from.
unique_id – The column name of the data to use as the agents unique_id. If “index”, the index of the GeoDataFrame is used. Default to “index”.
set_attributes – Set agent attributes from GeoDataFrame columns. Default True.
- from_file(filename, unique_id='index', set_attributes=True)[source]#
Create agents from vector data files (e.g. Shapefiles).
- Parameters:
filename – The vector data file to create agents from.
unique_id – The column name of the data to use as the agents unique_id. If “index”, the index of the GeoDataFrame is used. Default to “index”.
set_attributes – Set agent attributes from GeoDataFrame columns. Default True.
- from_GeoJSON(GeoJSON, unique_id='index', 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.
unique_id – The column name of the data to use as the agents unique_id. If “index”, the index of the GeoDataFrame is used. Default to “index”.
set_attributes – Set agent attributes from GeoDataFrame columns. Default True.