Skip to content

Commit

Permalink
Add zoom_adjust param to pygmt.datasets.load_tile_map and Figure.tilemap
Browse files Browse the repository at this point in the history
The zoom_adjust parameter is used to adjust the automatic zoom level by integer increments. This was added in contextily=1.5.0, see geopandas/contextily#228.
  • Loading branch information
weiji14 committed Dec 30, 2023
1 parent 75e56e5 commit 5ca369e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 15 additions & 1 deletion pygmt/datasets/tile_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
__doctest_requires__ = {("load_tile_map"): ["contextily"]}


def load_tile_map(region, zoom="auto", source=None, lonlat=True, wait=0, max_retries=2):
def load_tile_map(
region,
zoom="auto",
source=None,
lonlat=True,
wait=0,
max_retries=2,
zoom_adjust=None,
):
"""
Load a georeferenced raster tile map from XYZ tile providers.
Expand Down Expand Up @@ -79,6 +87,11 @@ def load_tile_map(region, zoom="auto", source=None, lonlat=True, wait=0, max_ret
will stop trying to fetch more tiles from a rate-limited API [Default
is ``2``].
zoom_adjust : int or None
Optional. The amount to adjust a chosen zoom level if it is chosen
automatically. Values outside of -1 to 1 are not recommended as they
can lead to slow execution. [Default is ``None``].
Returns
-------
raster : xarray.DataArray
Expand Down Expand Up @@ -128,6 +141,7 @@ def load_tile_map(region, zoom="auto", source=None, lonlat=True, wait=0, max_ret
ll=lonlat,
wait=wait,
max_retries=max_retries,
zoom_adjust=zoom_adjust,
)

# Turn RGBA img from channel-last to channel-first and get 3-band RGB only
Expand Down
16 changes: 15 additions & 1 deletion pygmt/src/tilemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@
)
@kwargs_to_strings(c="sequence_comma", p="sequence") # R="sequence",
def tilemap(
self, region, zoom="auto", source=None, lonlat=True, wait=0, max_retries=2, **kwargs
self,
region,
zoom="auto",
source=None,
lonlat=True,
wait=0,
max_retries=2,
zoom_adjust=None,
**kwargs,
):
r"""
Plots an XYZ tile map.
Expand Down Expand Up @@ -103,6 +111,11 @@ def tilemap(
will stop trying to fetch more tiles from a rate-limited API [Default
is ``2``].
zoom_adjust : int or None
Optional. The amount to adjust a chosen zoom level if it is chosen
automatically. Values outside of -1 to 1 are not recommended as they
can lead to slow execution. [Default is ``None``].
kwargs : dict
Extra keyword arguments to pass to :meth:`pygmt.Figure.grdimage`.
Expand Down Expand Up @@ -131,6 +144,7 @@ def tilemap(
lonlat=lonlat,
wait=wait,
max_retries=max_retries,
zoom_adjust=zoom_adjust,
)

# Reproject raster from Spherical Mercator (EPSG:3857) to
Expand Down

0 comments on commit 5ca369e

Please sign in to comment.