Skip to content

Commit

Permalink
tilemap: Use the new 'crs' parameter to simplify the tilemap function
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Nov 27, 2024
1 parent e744b00 commit d79af32
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions pygmt/src/tilemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias

try:
import rioxarray # noqa: F401
from xyzservices import TileProvider

_HAS_RIOXARRAY = True
except ImportError:
TileProvider = None
_HAS_RIOXARRAY = False


@fmt_docstring
Expand Down Expand Up @@ -111,38 +107,21 @@ def tilemap(
kwargs : dict
Extra keyword arguments to pass to :meth:`pygmt.Figure.grdimage`.
Raises
------
ImportError
If ``rioxarray`` is not installed. Follow
:doc:`install instructions for rioxarray <rioxarray:installation>`, (e.g. via
``python -m pip install rioxarray``) before using this function.
"""
kwargs = self._preprocess(**kwargs)

if not _HAS_RIOXARRAY:
raise ImportError(
"Package `rioxarray` is required to be installed to use this function. "
"Please use `python -m pip install rioxarray` or "
"`mamba install -c conda-forge rioxarray` to install the package."
)

raster = load_tile_map(
region=region,
zoom=zoom,
source=source,
lonlat=lonlat,
crs="OGC:CRS84" if lonlat is True else "EPSG:3857",
wait=wait,
max_retries=max_retries,
zoom_adjust=zoom_adjust,
)

# Reproject raster from Spherical Mercator (EPSG:3857) to lonlat (OGC:CRS84) if
# bounding box region was provided in lonlat
if lonlat and raster.rio.crs == "EPSG:3857":
raster = raster.rio.reproject(dst_crs="OGC:CRS84")
raster.gmt.gtype = 1 # set to geographic type
if lonlat:
raster.gmt.gtype = 1 # Set to geographic type

Check warning on line 124 in pygmt/src/tilemap.py

View check run for this annotation

Codecov / codecov/patch

pygmt/src/tilemap.py#L124

Added line #L124 was not covered by tests

# Only set region if no_clip is None or False, so that plot is clipped to exact
# bounding box region
Expand Down

0 comments on commit d79af32

Please sign in to comment.