Skip to content

Commit 97a6f30

Browse files
seismanweiji14
andauthored
load_tile_map: Register the rio accessor by importing rioxarray so the returned raster has CRS (#3323)
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
1 parent 480c671 commit 97a6f30

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pygmt/datasets/tile_map.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
:class:`xarray.DataArray`.
44
"""
55

6+
import contextlib
67
from typing import Literal
78

89
from packaging.version import Version
@@ -16,6 +17,10 @@
1617
TileProvider = None
1718
_HAS_CONTEXTILY = False
1819

20+
with contextlib.suppress(ImportError):
21+
# rioxarray is needed to register the rio accessor
22+
import rioxarray # noqa: F401
23+
1924
import numpy as np
2025
import xarray as xr
2126

@@ -117,6 +122,10 @@ def load_tile_map(
117122
* y (y) float64 ... -7.081e-10 -7.858e+04 ... -1.996e+07 -2.004e+07
118123
* x (x) float64 ... -2.004e+07 -1.996e+07 ... 1.996e+07 2.004e+07
119124
spatial_ref int64 ... 0
125+
>>> # CRS is set only if rioxarray is available
126+
>>> if hasattr(raster, "rio"):
127+
... raster.rio.crs
128+
CRS.from_epsg(3857)
120129
"""
121130
if not _HAS_CONTEXTILY:
122131
raise ImportError(

0 commit comments

Comments
 (0)