GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
747 stars 216 forks source link

Figure.tilemap: handle longitude given as 0°-360° #2591

Open yvonnefroehlich opened 1 year ago

yvonnefroehlich commented 1 year ago

pygmt.Figure.coast and the remote datasets (plotted via pygmt.Figure.grdimage) support that the longitude is given either as -180° to 180° East or as 0° to 360° East. However, it looks like the later longitude range is not supported by pygmt.Figure.tilemap. When plotting tiles for a region exceeding 180° East, the area after 180° East remains empty.

import pygmt as gmt

region_lon360 = [120, 190, -48, -9]

fig = gmt.Figure()

fig.tilemap(
    region=region_lon360,
    projection="M10c",
    zoom=2,
    frame=["WSne+ttilemap", "af"],
)

fig.shift_origin(xshift="11c")

fig.coast(
    region=region_lon360,
    projection="M10c",
    shorelines="1/1p,black",
    water="steelblue",
    frame=["wSne+tcoast", "af"],
)

fig.shift_origin(xshift="11c")

fig.grdimage(
    region=region_lon360,
    projection="M10c",
    grid="@earth_relief_01d_g",
    frame=["wSne+tremote dataset", "af"],
)

fig.show()
# fig.savefig(fname="tilemap_lon0to360.png")

Output figure: tilemap_lon0to360

weiji14 commented 1 year ago

Hmm, a few things:

  1. We should probably document that the lonlat range is from -180 to +180, or have a way of converting 0-360 coordinates to -180 to +180 before calling contextily.bounds2img. Specifically these lines https://github.com/GenericMappingTools/pygmt/blob/91e29f1c1b4ebef1244051e6b1e3742f16bc34a4/pygmt/datasets/tile_map.py#L27-L30 https://github.com/GenericMappingTools/pygmt/blob/91e29f1c1b4ebef1244051e6b1e3742f16bc34a4/pygmt/src/tilemap.py#L57-L60
  2. Ideally, the cross dateline support can be added upstream into contextily (or xyzservices?), and we should at least try to open up an issue to see if they're interested in handling it. I actually need to check if EPSG:3857 and EPSG:4326 tile servers actually support returning cross-dateline tiles. If not, then we may need to add the logic of fetching tiles to the West and East of the international dateline separately and stitch them back together.
seisman commented 1 year ago

2. Ideally, the cross dateline support can be added upstream into contextily (or xyzservices?), and we should at least try to open up an issue to see if they're interested in handling it.

Sounds good.