Summary
GeoSpace.layers is typed as a plain list, with no way to retrieve a specific
layer by name. In multi-layer models (e.g., flood zones, road networks, elevation
rasters), every agent step() that needs to interact with a specific layer requires
a manual for loop or next() workaround.
Environment
mesa: 3.0.x
mesa-geo: 0.9.x
Reproduction
# Attempting dict-style access raises TypeError
flood_layer = model.space.layers["flood_zone"]
# TypeError: list indices must be integers or slices, not str
# Current workaround required in every step() that needs a specific layer
flood_layer = next(
(l for l in self.model.space.layers if getattr(l, "name", None) == "flood_zone"),
None
)
Expected Behavior
A named lookup method on GeoSpace:
# Option A: explicit method
flood_layer = model.space.get_layer("flood_zone")
# Option B: dict-style access via __getitem__ override
flood_layer = model.space.layers["flood_zone"]
Either would eliminate the boilerplate that currently appears in every multi-layer
model's step() logic.
Proposed Implementation Notes
- Would require enforcing or strongly encouraging a
.name attribute on all layer
types (ImageLayer, RasterLayer, GeoDataFrame-backed layers).
get_layer(name) could raise KeyError if not found, consistent with dict behavior.
- Backward compatible,
layers as a list can remain accessible alongside the new method.
Context
This came up while building a flood evacuation simulation with separate layers for
road networks, flood extents, and elevation data. Targeting specific layers during
agent decision logic requires the same workaround in multiple places, which is a
friction point for any non-trivial geospatial model.
Summary
GeoSpace.layersis typed as a plainlist, with no way to retrieve a specificlayer by name. In multi-layer models (e.g., flood zones, road networks, elevation
rasters), every agent
step()that needs to interact with a specific layer requiresa manual
forloop ornext()workaround.Environment
mesa: 3.0.xmesa-geo: 0.9.xReproduction
Expected Behavior
A named lookup method on
GeoSpace:Either would eliminate the boilerplate that currently appears in every multi-layer
model's
step()logic.Proposed Implementation Notes
.nameattribute on all layertypes (
ImageLayer,RasterLayer,GeoDataFrame-backed layers).get_layer(name)could raiseKeyErrorif not found, consistent with dict behavior.layersas a list can remain accessible alongside the new method.Context
This came up while building a flood evacuation simulation with separate layers for
road networks, flood extents, and elevation data. Targeting specific layers during
agent decision logic requires the same workaround in multiple places, which is a
friction point for any non-trivial geospatial model.