def get_provider(self, provider_name, access_token=None): from bokeh.models.tiles import WMTSTileSource if isinstance(provider_name, WMTSTileSource): # This allows `get_provider(CARTODBPOSITRON)` to work if provider_name.startswith("MAPBOX"): if access_token is None: raise ValueError("provide access token for MAPBOX tiles") return WMTSTileSource( url=provider_name.url + str(access_token), attribution=provider_name.attribution, ) selected_provider = provider_name.upper() if selected_provider not in self.Vendors: raise ValueError("Unknown tile provider %s" % provider_name) url = self._SERVICE_URLS[selected_provider] if selected_provider.startswith("MAPBOX"): attribution = self._MAPBOX_ATTRIBUTION if access_token is None: raise ValueError("provide access token for MAPBOX tiles") return WMTSTileSource(url=url + str(access_token), attribution=attribution) else: raise ValueError("Can not retrieve attribution for %s" % selected_provider)
def STAMEN_TERRAIN_RETINA(self): from bokeh.models.tiles import WMTSTileSource return WMTSTileSource( url='http://tile.stamen.com/terrain/{Z}/{X}/{Y}@2x.png', attribution=self._STAMEN_ATTRIBUTION % '<a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>' )
def build_previewer(service: MapService): '''Helper function for creating a simple Bokeh figure with a WMTS Tile Source. Notes ----- - if you don't supply height / width, stretch_both sizing_mode is used. - supply an output_dir to write figure to disk. ''' xmin, ymin, xmax, ymax = service.default_extent p = figure(sizing_mode='stretch_both', x_range=(xmin, xmax), y_range=(ymin, ymax), toolbar_location='above', tools="pan,wheel_zoom,reset") tile_provider = get_provider(STAMEN_TONER_BACKGROUND) p.add_tile(tile_provider, alpha=.1) p.background_fill_color = 'black' p.grid.grid_line_alpha = 0 p.axis.visible = True if service.service_type == 'tile': tile_source = WMTSTileSource(url=service.client_url, min_zoom=0, max_zoom=15) p.add_tile(tile_source, render_parents=False) p.axis.visible = False return p
def tile_previewer(full_extent, tileset_url, output_dir=None, filename='index.html', title='Datashader Tileset', min_zoom=0, max_zoom=40, height=None, width=None, **kwargs): '''Helper function for creating a simple Bokeh figure with a WMTS Tile Source. Notes ----- - if you don't supply height / width, stretch_both sizing_mode is used. - supply an output_dir to write figure to disk. ''' try: from bokeh.plotting import figure from bokeh.models.tiles import WMTSTileSource from bokeh.io import output_file, save from os import path except ImportError: raise ImportError( 'conda install bokeh to enable creation of simple tile viewer') if output_dir: output_file(filename=path.join(output_dir, filename), title=title) xmin, ymin, xmax, ymax = full_extent if height and width: p = figure(width=width, height=height, x_range=(xmin, xmax), y_range=(ymin, ymax), tools="pan,wheel_zoom,reset", **kwargs) else: p = figure(sizing_mode='stretch_both', x_range=(xmin, xmax), y_range=(ymin, ymax), tools="pan,wheel_zoom,reset", **kwargs) p.background_fill_color = 'black' p.grid.grid_line_alpha = 0 p.axis.visible = True tile_source = WMTSTileSource(url=tileset_url, min_zoom=min_zoom, max_zoom=max_zoom) p.add_tile(tile_source, render_parents=False) if output_dir: save(p) return p
def CARTODBPOSITRON(self): from bokeh.util.deprecation import deprecated deprecated(since_or_msg=(2, 0, 0), old='CARTODBPOSITRON', new='get_provider(Provider.CARTODBPOSITRON)') from bokeh.models.tiles import WMTSTileSource return WMTSTileSource( url='https://tiles.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', attribution=self._CARTO_ATTRIBUTION)
def _init_bokeh_map(self): lg.info('>> TS STATE: {}'.format(self.env.ts_state)) if self.env.ts_state is None: # this should not happen, I add it here just in case self.env.ts_state = 'online' # I set online because I cannot run tile server from here if self.env.ts_state == 'online': tile_options = dict(url=ARGIS_TS) else: tile_options = dict(url=LOCAL_TS) tile_source = WMTSTileSource(**tile_options) range_padding = 0.30 # TODO: when a profile is selected, the range size is changed?? x_range = DataRange1d(range_padding=range_padding, # range_padding_units='absolute', ) y_range = DataRange1d(range_padding=range_padding, # range_padding_units='absolute', ) self.env.wmts_map = Figure( plot_height=240, plot_width=200, output_backend=OUTPUT_BACKEND, tools='', toolbar_location='right', x_axis_type='mercator', # to avoid weird axis numbers y_axis_type='mercator', y_axis_location='left', x_range=x_range, y_range=y_range, border_fill_color= 'whitesmoke', # TODO: this should be declared on the yaml file background_fill_color='whitesmoke') self.env.wmts_map.axis.visible = True self.env.wmts_map.add_tile(tile_source) self.env.wmts_map_scatter = self.env.wmts_map.circle( x='X_WMTS', y='Y_WMTS', size=4, source=self.env.wmts_map_source, # color='#00FF00', # marker='circle', # value by default line_color=None, fill_color='#000e7a', fill_alpha=1.0, nonselection_line_color=None, nonselection_fill_color='#000e7a', nonselection_fill_alpha=1.0, ) self.env.wmts_map_scatter.selection_glyph = Circle( line_color=RED, line_alpha=1.0, fill_color='yellow', )
def STAMEN_TONER_LABELS(self): from bokeh.util.deprecation import deprecated deprecated(since_or_msg=(2, 0, 0), old='STAMEN_TONER_LABELS', new='get_provider(Provider.STAMEN_TONER_LABELS)') from bokeh.models.tiles import WMTSTileSource return WMTSTileSource( url='http://tile.stamen.com/toner-labels/{Z}/{X}/{Y}.png', attribution=self._STAMEN_ATTRIBUTION % '<a href="https://www.openstreetmap.org/copyright">ODbL</a>')
def STAMEN_TERRAIN_RETINA(self): from bokeh.util.deprecation import deprecated deprecated(since_or_msg=(2, 0, 0), old='STAMEN_TERRAIN_RETINA', new='get_provider(provider.STAMEN_TERRAIN_RETINA)') from bokeh.models.tiles import WMTSTileSource return WMTSTileSource( url='http://tile.stamen.com/terrain/{Z}/{X}/{Y}@2x.png', attribution=self._STAMEN_ATTRIBUTION % '<a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>' )
def _make_tile_provider(selected_provider): url = selected_provider.value if selected_provider.name.startswith('CARTO'): attribution = _TileProvidersModule._CARTO_ATTRIBUTION elif selected_provider.name.startswith('STAMEN'): attribution = _TileProvidersModule._STAMEN_ATTRIBUTION else: raise ValueError('Can not retrieve attribution for {0}'.format( selected_provider)) from bokeh.models.tiles import WMTSTileSource return WMTSTileSource(url=url, attribution=attribution)
def plot_filtered(col, fdf, background = 'black', Toner=True, x_range = (1373757.1102773394, 1412506.1502695908), y_range = (7478418.9895278225, 7520786.118694777)): """ """ p = base_plot(x_range = x_range, y_range = y_range) if Toner: url="http://tile.stamen.com/toner-background/{Z}/{X}/{Y}.png" else: url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}.png" tile_renderer = p.add_tile(WMTSTileSource(url=url)) tile_renderer.alpha=1.0 if background == "black" else 0.15 return InteractiveImage(p, create_image_wrap(col, fdf, x_range = x_range, y_range = y_range))
def get_provider(self, provider_name): from bokeh.models.tiles import WMTSTileSource if isinstance(provider_name, WMTSTileSource): # This allows `get_provider(CARTODBPOSITRON)` to work return WMTSTileSource(url=provider_name.url, attribution=provider_name.attribution) selected_provider = provider_name.upper() if selected_provider not in self.Vendors: raise ValueError('Unknown tile provider %s' % provider_name) url = self._SERVICE_URLS[selected_provider] if selected_provider.startswith('CARTO'): attribution = self._CARTO_ATTRIBUTION elif selected_provider.startswith('STAMEN'): attribution = self._STAMEN_ATTRIBUTION % self._STAMEN_ATTRIBUTION_URLS[ selected_provider] else: raise ValueError('Can not retrieve attribution for %s' % selected_provider) return WMTSTileSource(url=url, attribution=attribution)
def STAMEN_TONER_LABELS(self): from bokeh.models.tiles import WMTSTileSource return WMTSTileSource( url='http://tile.stamen.com/toner-labels/{Z}/{X}/{Y}.png', attribution=self._STAMEN_ATTRIBUTION % '<a href="https://www.openstreetmap.org/copyright">ODbL</a>')
def CARTODBPOSITRON_RETINA(self): from bokeh.models.tiles import WMTSTileSource return WMTSTileSource( url= 'https://tiles.basemaps.cartocdn.com/light_all/{z}/{x}/{y}@2x.png', attribution=self._CARTO_ATTRIBUTION)
def nlmaps(): from bokeh.models.tiles import WMTSTileSource return WMTSTileSource(attribution="© Copyright <a href='https://kadaster.nl/'>Kadaster</a>, Product by Marnix Ober. All rights reserved.", url="https://geodata.nationaalgeoregister.nl/tiles/service/wmts/brtachtergrondkaart/EPSG:3857/{Z}/{X}/{Y}.png")
def _get_tilesource(source='hikebike'): src = TILE_SOURCES[source] return WMTSTileSource( url=src['url'], attribution=src['attrib'], )