GeoSpace#

class GeoSpace(crs='epsg:3857', *, warn_crs_conversion=True)[source]#

Space used to add a geospatial component to a model.

Create a GeoSpace for GIS enabled mesa modeling.

Parameters:
  • crs – The coordinate reference system of the GeoSpace. If crs is not set, epsg:3857 (Web Mercator) is used as default. However, this system is only accurate at the equator and errors increase with latitude.

  • warn_crs_conversion – Whether to warn when converting layers and GeoAgents of different crs into the crs of GeoSpace. Default to True.

to_crs(crs, inplace=False) GeoSpace | 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

property transformer#

Return the pyproj.Transformer that transforms the GeoSpace into epsg:4326. Mainly used for GeoJSON serialization.

property agents#

Return a list of all agents in the Geospace.

property layers: list[ImageLayer | RasterLayer | gpd.GeoDataFrame]#

Return a list of all layers in the Geospace.

property total_bounds: np.ndarray | None#

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

add_layer(layer: ImageLayer | RasterLayer | gpd.GeoDataFrame) None[source]#

Add a layer to the Geospace.

Parameters:

layer (ImageLayer | RasterLayer | gpd.GeoDataFrame) – The layer to add.

add_agents(agents)[source]#

Add a list of GeoAgents to the Geospace.

GeoAgents must have a geometry attribute. This function may also be called with a single GeoAgent.

Parameters:

agents – A list of GeoAgents or a single GeoAgent to be added into GeoSpace.

Raises:

AttributeError – If the GeoAgents do not have a geometry attribute.

remove_agent(agent)[source]#

Remove an agent from the GeoSpace.

get_relation(agent, relation)[source]#

Return a list of related agents.

Parameters:
  • agent (GeoAgent) – The agent to find related agents for.

  • relation (str) – The relation to find. Must be one of ‘intersects’, ‘within’, ‘contains’, ‘touches’.

get_intersecting_agents(agent)[source]#
get_neighbors_within_distance(agent, distance, center=False, relation='intersects')[source]#

Return a list of agents within distance of agent.

Distance is measured as a buffer around the agent’s geometry, set center=True to calculate distance from center.

agents_at(pos)[source]#

Return a list of agents at given pos.

distance(agent_a, agent_b)[source]#

Return distance of two agents.

get_neighbors(agent)[source]#

Get (touching) neighbors of an agent.

get_agents_as_GeoDataFrame(agent_cls=<class 'mesa_geo.geoagent.GeoAgent'>) GeoDataFrame[source]#

Extract GeoAgents as a GeoDataFrame.

Parameters:

agent_cls – The class of the GeoAgents to extract. Default is GeoAgent.

Returns:

A GeoDataFrame of the GeoAgents.

Return type:

gpd.GeoDataFrame

property crs: pyproj.CRS | None#

Return the coordinate reference system of the object.