Skip to content

Commit

Permalink
Merge pull request #1203 from gboeing/vrt
Browse files Browse the repository at this point in the history
replace gdal optional dependency with rio-vrt
  • Loading branch information
gboeing authored Aug 20, 2024
2 parents 857da27 + 42ba574 commit e4bce53
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions environments/docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# basics
osmnx
rio-vrt
python == 3.12.*

# helpful extras
Expand Down
2 changes: 1 addition & 1 deletion environments/tests/env-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ dependencies:
- shapely

# extras
- gdal
- matplotlib
- rasterio
- rio-vrt
- scikit-learn
- scipy

Expand Down
2 changes: 1 addition & 1 deletion environments/tests/env-test-minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.3
- scikit-learn=0.23
- scipy=1.5

Expand Down
13 changes: 6 additions & 7 deletions osmnx/elevation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.3"]
visualization = ["matplotlib>=3.5"]

[project.urls]
Expand Down

0 comments on commit e4bce53

Please sign in to comment.