Skip to content

Commit

Permalink
Allow passing bokeh tile source URL to WMTS
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Aug 17, 2017
1 parent a144268 commit 18a6af1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
11 changes: 8 additions & 3 deletions geoviews/element/geo.py
Expand Up @@ -24,6 +24,11 @@
except:
WMTSTileSource = None

try:
from owslib.wmts import WebMapTileService
except:
WebMapTileService = None

geographic_types = (cGoogleTiles, cFeature)

def is_geographic(element, kdims=None):
Expand Down Expand Up @@ -141,13 +146,13 @@ def __init__(self, data, **params):
if WMTSTileSource and isinstance(d, WMTSTileSource):
if 'crs' not in params:
params['crs'] = ccrs.GOOGLE_MERCATOR
elif not isinstance(data, basestring):
elif WebMapTileService and isinstance(d, WebMapTileService):
if 'crs' not in params and not self.crs:
raise Exception('Must supply coordinate reference '
'system with cartopy WMTS URL.')
else:
elif not isinstance(d, basestring):
raise TypeError('%s data has to be a tile service URL'
% type(data).__name__)
% type(d).__name__)
super(WMTS, self).__init__(data, **params)


Expand Down
20 changes: 15 additions & 5 deletions geoviews/plotting/bokeh/__init__.py
Expand Up @@ -81,12 +81,22 @@ class TilePlot(GeoPlot):
style_opts = ['alpha', 'render_parents']

def get_data(self, element, ranges=None, empty=False):
tile_sources = [ts for ts in element.data
if isinstance(ts, WMTSTileSource)]
if not tile_sources:
raise SkipRendering("No valid WMTSTileSource found in WMTS "
tile_source = None
for url in element.data:
if isinstance(url, util.basestring) and not url.endswith('cgi'):
try:
tile_source = WMTSTileSource(url=url)
break
except:
pass
elif isinstance(url, WMTSTileSource):
tile_source = url
break

if tile_source is None:
raise SkipRendering("No valid tile source URL found in WMTS "
"Element, rendering skipped.")
return {}, {'tile_source': tile_sources[0]}
return {}, {'tile_source': tile_source}

def _update_glyph(self, renderer, properties, mapping, glyph):
allowed_properties = glyph.properties()
Expand Down
27 changes: 23 additions & 4 deletions geoviews/plotting/mpl/__init__.py
Expand Up @@ -3,6 +3,12 @@
import numpy as np
import param
from cartopy import crs as ccrs

try:
from owslib.wmts import WebMapTileService
except:
WebMapTileService = None

from holoviews.core import (Store, HoloMap, Layout, Overlay,
CompositeOverlay, Element, NdLayout)
from holoviews.core import util
Expand Down Expand Up @@ -378,12 +384,25 @@ class WMTSPlot(GeoPlot):
'filterrad', 'clims', 'norm']

def get_data(self, element, ranges, style):
tile_sources = [ts for ts in element.data
if isinstance(ts, util.basestring)]
if not tile_sources:
if WebMapTileService is None:
raise SkipRendering('WMTS element requires owslib and PIL '
'to be installed.')
tile_source = None
for url in element.data:
if isinstance(url, util.basestring):
try:
tile_source = WebMapTileService(url)
break
except:
pass
elif isinstance(url, WebMapTileService):
tile_source = url
break

if tile_source is None:
raise SkipRendering("No valid tile source URL found in WMTS "
"Element, rendering skipped.")
return (tile_sources[0], element.layer), style, {}
return (tile_source, element.layer), style, {}

def init_artists(self, ax, plot_args, plot_kwargs):
return {'artist': ax.add_wmts(*plot_args, **plot_kwargs)}
Expand Down

0 comments on commit 18a6af1

Please sign in to comment.