Skip to content

Commit

Permalink
Added support for MercatorTicker in bokeh
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Sep 29, 2017
1 parent 022a5d2 commit 77b52e6
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions geoviews/plotting/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import shapely.geometry
from cartopy.crs import GOOGLE_MERCATOR
from bokeh.models import WMTSTileSource
from bokeh.models import WMTSTileSource, MercatorTickFormatter, MercatorTicker
from bokeh.models.tools import BoxZoomTool

from holoviews import Store, Overlay, NdOverlay
Expand All @@ -16,13 +16,15 @@
from holoviews.plotting.bokeh.chart import PointPlot
from holoviews.plotting.bokeh.path import PolygonPlot, PathPlot
from holoviews.plotting.bokeh.raster import RasterPlot
from holoviews.plotting.bokeh.util import IGNORED_MODELS

from ...element import (WMTS, Points, Polygons, Path, Shape, Image,
Feature, is_geographic, Text, _Element)
from ...operation import project_image
from ...util import project_extents, geom_to_array

DEFAULT_PROJ = GOOGLE_MERCATOR
IGNORED_MODELS += ['MercatorTicker', 'MercatorTickFormatter']

line_types = (shapely.geometry.MultiLineString, shapely.geometry.LineString)
poly_types = (shapely.geometry.MultiPolygon, shapely.geometry.Polygon)
Expand All @@ -44,14 +46,26 @@ def __init__(self, element, **params):
super(GeoPlot, self).__init__(element, **params)
self.geographic = is_geographic(self.hmap.last)


def _axis_properties(self, axis, key, plot, dimension=None,
ax_mapping={'x': 0, 'y': 1}):
axis_props = super(GeoPlot, self)._axis_properties(axis, key, plot,
dimension, ax_mapping)
if self.geographic:
dimension = 'lon' if axis == 'x' else 'lat'
axis_props['ticker'] = MercatorTicker(dimension=dimension)
axis_props['formatter'] = MercatorTickFormatter(dimension=dimension)
return axis_props


def get_extents(self, element, ranges):
"""
Subclasses the get_extents method using the GeoAxes
set_extent method to project the extents to the
Elements coordinate reference system.
"""
extents = super(GeoPlot, self).get_extents(element, ranges)
if not getattr(element, 'crs', None):
if not getattr(element, 'crs', None) or not self.geographic:
return extents
elif any(e is None or not np.isfinite(e) for e in extents):
extents = None
Expand All @@ -63,17 +77,18 @@ def get_extents(self, element, ranges):
return (np.NaN,)*4 if not extents else extents


class OverlayPlot(HvOverlayPlot):

class OverlayPlot(GeoPlot, HvOverlayPlot):
"""
Subclasses the HoloViews OverlayPlot to add custom behavior
for geographic plots.
"""

def __init__(self, element, **params):
super(OverlayPlot, self).__init__(element, **params)
self.geographic = any(element.traverse(is_geographic, [_Element]))
if self.geographic:
self.show_grid = False
super(OverlayPlot, self).__init__(element, **params)


class TilePlot(GeoPlot):
Expand Down

0 comments on commit 77b52e6

Please sign in to comment.