Skip to content

Commit fc4028b

Browse files
authored
Expose rasterio's opener argument in Rasterlayer.from_file This commit allows passing Rasterio's new opener argument from the RasterLayer.from_file() method. This allows for easier reading of gzip files, among others. (#237)
1 parent 93f04f6 commit fc4028b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

mesa_geo/raster_layers.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import itertools
1010
import math
1111
import uuid
12-
from collections.abc import Iterable, Iterator, Sequence
12+
from collections.abc import Callable, Iterable, Iterator, Sequence
1313
from typing import Any, cast, overload
1414

1515
import numpy as np
@@ -533,7 +533,11 @@ def to_image(self, colormap) -> ImageLayer:
533533

534534
@classmethod
535535
def from_file(
536-
cls, raster_file: str, cell_cls: type[Cell] = Cell, attr_name: str | None = None
536+
cls,
537+
raster_file: str,
538+
cell_cls: type[Cell] = Cell,
539+
attr_name: str | None = None,
540+
rio_opener: Callable | None = None,
537541
) -> RasterLayer:
538542
"""
539543
Creates a RasterLayer from a raster file.
@@ -542,9 +546,10 @@ def from_file(
542546
:param Type[Cell] cell_cls: The class of the cells in the layer.
543547
:param str | None attr_name: The name of the attribute to use for the cell values.
544548
If None, a random name will be generated. Default is None.
549+
:param Callable | None rio_opener: A callable passed to Rasterio open() function.
545550
"""
546551

547-
with rio.open(raster_file, "r") as dataset:
552+
with rio.open(raster_file, "r", opener=rio_opener) as dataset:
548553
values = dataset.read()
549554
_, height, width = values.shape
550555
total_bounds = [

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dependencies = [
4343
"geopandas",
4444
"libpysal",
4545
"rtree",
46-
"rasterio",
46+
"rasterio>=1.4b1",
4747
"shapely",
4848
"pyproj",
4949
"folium",

0 commit comments

Comments
 (0)