-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration with contextily to plot xyz basemaps #2115
Comments
Can we do both 1 and 2? I.e., having the |
That sounds like a neat idea. Start with (2) Actually, we'll also need to let |
Started a Pull Request at #2125 for To jump ahead a little bit, this is the code I'm currently using to plot the 3-band import pygmt
import rioxarray
raster.rio.to_raster(raster_path="basemap.tif")
fig = pygmt.Figure()
fig.grdimage(grid="basemap.tif", frame=True)
fig.savefig("Singapore_stamen_map.png")
fig.show() produces this Stamen Terrain map over Singapore |
After a bit of thinking, and as mentioned in in #2125 (comment), I'm considering creating a new def tilemap(self, *, **kwargs):
with GMTTempFile(suffix=".tif") as tmpfile:
raster = pygmt.datasets.load_tile_map(...)
raster.rio.to_raster(raster_path=tmpfile.name)
fig.grdimage(grid=tmpfile.name, **kwargs) Any thoughts on this implementation? Note that projections will also need to be handled, something mentioned in #2125 (comment). Also, the The tempfile is a bit of a hack to be honest, but is necessary until we can use |
Yes, I aslo prefer
I agree. |
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.On the implementation, here are 2 ideas on how to integrate
contextily
basemaps withpygmt
.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 calledfig.tilemap
)load_basemap
function underpygmt/datasets
that would load the image (np.ndarray
) and georeference it (to anxarray.DataArray
), and then the user plots it usingfig.grdimage
. (done at Add function to load raster tile maps using contextily #2125, calledload_tile_map
)Either way, these would require:
contextily.bounds2img
function at https://contextily.readthedocs.io/en/latest/reference.html#contextily.bounds2img. This returns anumpy.ndarray
and a geographic extent.numpy.ndarray
needs to be georeferenced into anxarray.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 thatxarray.DataArray
will need to be plotted on the PyGMT mapAre you willing to help implement and maintain this feature? Yes, but discuss about the implementation first
The text was updated successfully, but these errors were encountered: