Skip to content
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

Add support for xyzservices #654

Merged
merged 4 commits into from
Jun 16, 2023
Merged

Add support for xyzservices #654

merged 4 commits into from
Jun 16, 2023

Conversation

ahuang11
Copy link
Collaborator

@ahuang11 ahuang11 commented Jun 15, 2023

Closes #517 and finishes holoviz/holoviews#5057

Based off https://github.com/holoviz/holoviews/pull/5062/files

import geoviews as gv
import xyzservices.providers as xyz
gv.extension("bokeh")

gv.WMTS(xyz.NASAGIBS.ViirsEarthAtNight2012)
image

@ahuang11 ahuang11 requested a review from hoxbro June 15, 2023 17:27
@ahuang11 ahuang11 marked this pull request as ready for review June 15, 2023 17:27
Copy link
Member

@hoxbro hoxbro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments

geoviews/tests/plotting/bokeh/test_tiles.py Show resolved Hide resolved
geoviews/element/geo.py Outdated Show resolved Hide resolved
geoviews/plotting/bokeh/__init__.py Show resolved Hide resolved
These variables correspond to three different formats for specifying the spatial
location and zoom level of the requested tiles:

* Web mapping tiles sources containing {x}, {y}, and {z} variables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused by this change. You are changing the WMTS class to contain WMTS, QUADKEY, and BBox.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, it already supported all those; it just wasn't documented.

tile_source = QUADKEYTileSource
elif all(kw in element.data.upper() for kw in ('{XMIN}', '{XMAX}', '{YMIN}', '{YMAX}')):
tile_source = BBoxTileSource
elif all(kw in element.data.upper() for kw in ('{X}', '{Y}', '{Z}')):
tile_source = WMTSTileSource

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class WMTSPlot(GeoPlot):
"""
Adds a Web Map Tile Service from a WMTS Element.
"""
zoom = param.Integer(default=8, doc="""
Controls the zoom level of the tile source.""")
style_opts = ['alpha', 'cmap', 'interpolation', 'visible',
'filterrad', 'clims', 'norm']
def get_data(self, element, ranges, style):
if isinstance(element.data, str):
if '{Q}' in element.data:
tile_source = QuadtreeTiles(url=element.data)
else:
tile_source = GoogleTiles(url=element.data)
return (tile_source, self.zoom), style, {}
else:
tile_source = element.data
return (tile_source, element.layer), style, {}
def init_artists(self, ax, plot_args, plot_kwargs):
if isinstance(plot_args[0], GoogleTiles):
if 'artist' in self.handles:
return {'artist': self.handles['artist']}
img = ax.add_image(*plot_args, **plot_kwargs)
return {'artist': img or plot_args[0]}
return {'artist': ax.add_wmts(*plot_args, **plot_kwargs)}
def teardown_handles(self):
"""
If no custom update_handles method is supplied this method
is called to tear down any previous handles before replacing
them.
"""
if not isinstance(self.handles.get('artist'), GoogleTiles):
self.handles['artist'].remove()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, it already supported all those; it just wasn't documented.

Isn't this something you added to this PR?

It just doesn't make sense to me to have a specific name for the class and then support more general cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this PR only adds support for XYZServices' classes (the package).

Yes, I understand that, but it'd be breaking change if we separated those out.

Copy link
Collaborator Author

@ahuang11 ahuang11 Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, this URL uses BBoxTileSource and all I'm using is gv.WMTS

radar_url_fmt = """
https://idpgis.ncep.noaa.gov/arcgis/services/radar/radar_base_reflectivity_time/ImageServer/WMSServer?
SERVICE=WMS
&VERSION=1.3.0
&REQUEST=GetMap
&FORMAT=image/png
&TRANSPARENT=true
&WIDTH=256
&HEIGHT=256
&CRS=EPSG:3857
&BBOX={XMIN},{YMIN},{XMAX},{YMAX}
&LAYERS=0
"""

to render it
image

https://ahuang11.github.io/web-map-feature-services-cookbook/notebooks/web_map_services.html#accessing-external-sources

Maybe we can deprecate gv.WMTS in favor of gv.Tiles

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got confused by the way Github highlighted stuff.

I think we should think about giving it a broader name for the class (but not in this PR).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can deprecate gv.WMTS in favor of gv.Tiles

I think this would be a good idea. Let's do it in another PR.

@ahuang11 ahuang11 requested a review from hoxbro June 16, 2023 14:28
@ahuang11 ahuang11 merged commit 5c92ad6 into main Jun 16, 2023
@ahuang11 ahuang11 deleted the xyzservices_support branch June 16, 2023 16:44
ahuang11 added a commit that referenced this pull request Jun 27, 2023
Co-authored-by: Andrew Huang <ahuang@Andrews-MacBook-Pro.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support xyzservices for tile management
2 participants