Skip to content

GeoSpace.layers is a plain list with no named lookup, making multi-layer models ergonomically painfulΒ #324

Description

@Tejasv-Singh

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions