Skip to content

Commit

Permalink
compat: rasterio 1.4.2 (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Nov 10, 2024
1 parent 2fbf772 commit 79cde9d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions geoviews/util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from contextlib import suppress

import numpy as np
import shapely
import shapely.geometry as sgeom
Expand Down Expand Up @@ -652,9 +654,16 @@ def from_xarray(da, crs=None, apply_transform=False, nan_nodata=False, **kwargs)
'defaulting to non-geographic element.')
elif hasattr(da, 'rio') and da.rio.crs is not None:
# rioxarray.open_rasterio
try:
kwargs['crs'] = process_crs(da.rio.crs.to_proj4())
except Exception:
crs = None
# to handle rasterio 1.4.1 vs 1.4.2 differences
# https://github.com/holoviz/geoviews/pull/763
for method_name in ("to_epsg", "to_proj4"):
with suppress(Exception):
crs = process_crs(getattr(da.rio.crs, method_name)())
break
if crs:
kwargs['crs'] = crs
else:
warn(f'Could not decode projection from crs string {da.rio.crs}, '
'defaulting to non-geographic element.')

Expand Down

0 comments on commit 79cde9d

Please sign in to comment.