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.

  • 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.

  • crs – The coordinate reference system to transform to.

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


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.


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


Add a list of GeoAgents to the Geospace.

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


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


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


Remove an agent from the GeoSpace.

get_relation(agent, relation)[source]#

Return a list of related agents.

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

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

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.


Return a list of agents at given pos.

distance(agent_a, agent_b)[source]#

Return distance of two agents.


Get (touching) neighbors of an agent.

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

Extract GeoAgents as a GeoDataFrame.


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


A GeoDataFrame of the GeoAgents.

Return type:


property crs: pyproj.CRS | None#

Return the coordinate reference system of the object.