diff --git a/mesa_geo/raster_layers.py b/mesa_geo/raster_layers.py index 98406b6c..a39c7b15 100644 --- a/mesa_geo/raster_layers.py +++ b/mesa_geo/raster_layers.py @@ -9,7 +9,7 @@ import itertools import math import uuid -from collections.abc import Iterable, Iterator, Sequence +from collections.abc import Callable, Iterable, Iterator, Sequence from typing import Any, cast, overload import numpy as np @@ -533,7 +533,11 @@ def to_image(self, colormap) -> ImageLayer: @classmethod def from_file( - cls, raster_file: str, cell_cls: type[Cell] = Cell, attr_name: str | None = None + cls, + raster_file: str, + cell_cls: type[Cell] = Cell, + attr_name: str | None = None, + rio_opener: Callable | None = None, ) -> RasterLayer: """ Creates a RasterLayer from a raster file. @@ -542,9 +546,10 @@ def from_file( :param Type[Cell] cell_cls: The class of the cells in the layer. :param str | None attr_name: The name of the attribute to use for the cell values. If None, a random name will be generated. Default is None. + :param Callable | None rio_opener: A callable passed to Rasterio open() function. """ - with rio.open(raster_file, "r") as dataset: + with rio.open(raster_file, "r", opener=rio_opener) as dataset: values = dataset.read() _, height, width = values.shape total_bounds = [ diff --git a/pyproject.toml b/pyproject.toml index 0c0f1751..df22e10b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ dependencies = [ "geopandas", "libpysal", "rtree", - "rasterio", + "rasterio>=1.4b1", "shapely", "pyproj", "folium",