diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cfd2dfe..9743eeb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Read the v2 [migration guide](https://github.com/gboeing/osmnx/issues/1123) - drop Python 3.8 support (#1106) - bump minimum required numpy version to 1.22 for typing support (#1133 #1198) - bump minimum required versions of geopandas to 1.0 and pandas to 1.4 for union_all support (#1179 #1198) +- replace gdal optional dependency with rio-vrt optional dependency (#1203) - improve docstrings throughout package (#1116) - improve logging and warnings throughout package (#1125) - improve error messages throughout package (#1131) diff --git a/environments/docker/requirements.txt b/environments/docker/requirements.txt index 03c575d1..4e0f82d2 100644 --- a/environments/docker/requirements.txt +++ b/environments/docker/requirements.txt @@ -1,5 +1,6 @@ # basics osmnx +rio-vrt python == 3.12.* # helpful extras diff --git a/environments/tests/env-ci.yml b/environments/tests/env-ci.yml index f2f916ba..b90b48d2 100644 --- a/environments/tests/env-ci.yml +++ b/environments/tests/env-ci.yml @@ -13,9 +13,9 @@ dependencies: - shapely # extras - - gdal - matplotlib - rasterio + - rio-vrt - scikit-learn - scipy diff --git a/environments/tests/env-test-minimal.yml b/environments/tests/env-test-minimal.yml index b5671f12..9f3825b1 100644 --- a/environments/tests/env-test-minimal.yml +++ b/environments/tests/env-test-minimal.yml @@ -17,9 +17,9 @@ dependencies: - shapely=2.0 # extras (pinned to min versions from /pyproject.toml) - - gdal - matplotlib=3.5 - rasterio=1.3 + - rio-vrt=0.2 - scikit-learn=0.23 - scipy=1.5 diff --git a/osmnx/elevation.py b/osmnx/elevation.py index d8ec0a83..91764b23 100644 --- a/osmnx/elevation.py +++ b/osmnx/elevation.py @@ -24,13 +24,13 @@ if TYPE_CHECKING: from collections.abc import Iterable -# rasterio and gdal are optional dependencies for raster querying +# rasterio and rio-vrt are optional dependencies for raster querying try: import rasterio - from osgeo import gdal + from rio_vrt import build_vrt except ImportError: # pragma: no cover rasterio = None - gdal = None + build_vrt = None def add_edge_grades(G: nx.MultiDiGraph, *, add_absolute: bool = True) -> nx.MultiDiGraph: @@ -137,8 +137,8 @@ def add_node_elevations_raster( G Graph with `elevation` attributes on the nodes. """ - if rasterio is None or gdal is None: # pragma: no cover - msg = "gdal and rasterio must be installed as optional dependencies to query raster files." + if rasterio is None or build_vrt is None: # pragma: no cover + msg = "rasterio and rio-vrt must be installed as optional dependencies to query rasters." raise ImportError(msg) if cpus is None: @@ -153,8 +153,7 @@ def add_node_elevations_raster( filepaths = [str(p) for p in filepath] checksum = sha1(str(filepaths).encode("utf-8")).hexdigest() # noqa: S324 filepath = f"./.osmnx_{checksum}.vrt" - gdal.UseExceptions() - gdal.BuildVRT(filepath, filepaths).FlushCache() + build_vrt(filepath, filepaths) nodes = convert.graph_to_gdfs(G, edges=False, node_geometry=False)[["x", "y"]] if cpus == 1: diff --git a/pyproject.toml b/pyproject.toml index 7b7208a8..0eb03ea1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ requires-python = ">=3.9" # match classifiers above and ruff/mypy versions below [project.optional-dependencies] entropy = ["scipy>=1.5"] neighbors = ["scikit-learn>=0.23", "scipy>=1.5"] -raster = ["gdal", "rasterio>=1.3"] +raster = ["rasterio>=1.3", "rio-vrt>=0.2"] visualization = ["matplotlib>=3.5"] [project.urls]