Skip to content

Integration with contextily to plot xyz basemaps #2115

@weiji14

Description

@weiji14

Description of the desired feature

To allow for a greater variety of basemaps from e.g. OpenStreetMap, Stamen, MapBox, etc, it would be nice to integrate with contextily (part of the geopandas organization). This is motivated by https://forum.generic-mapping-tools.org/t/pygmt-vs-plotly/3250/10.

image

On the implementation, here are 2 ideas on how to integrate contextily basemaps with pygmt.

  1. Have an additional option under fig.basemap which allows selection of the basemap (e.g. OpenStreetMap, Stamen, Mapbox, etc) (Add Figure.tilemap to plot XYZ tile maps #2394, to be called fig.tilemap)
  2. Create a new load_basemap function under pygmt/datasets that would load the image (np.ndarray) and georeference it (to an xarray.DataArray), and then the user plots it using fig.grdimage. (done at Add function to load raster tile maps using contextily #2125, called load_tile_map)
  3. Maybe there's another more Pythonic way? Comment down below!

Either way, these would require:

  1. Wrapping around the contextily.bounds2img function at https://contextily.readthedocs.io/en/latest/reference.html#contextily.bounds2img. This returns a numpy.ndarray and a geographic extent.
  2. The numpy.ndarray needs to be georeferenced into an xarray.DataArray. I have some recent code at https://zen3geo.readthedocs.io/en/v0.4.0/object-detection-boxes.html#georeference-image-using-rioxarray to do that
  3. The xarray.DataArray will need to be plotted on the PyGMT map

Are you willing to help implement and maintain this feature? Yes, but discuss about the implementation first

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions