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

Added Labels and HexTiles elements #147

Merged
merged 1 commit into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion geoviews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
WMTS, LineContours, FilledContours, Text, Image,
Points, Path, Polygons, Shape, Dataset, RGB,
Contours, Graph, TriMesh, Nodes, EdgePaths,
QuadMesh, VectorField)
QuadMesh, VectorField, HexTiles, Labels)
from . import data # noqa (API import)
from . import operation # noqa (API import)
from . import plotting # noqa (API import)
Expand Down
2 changes: 1 addition & 1 deletion geoviews/element/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
WMTS, Points, Image, Text, LineContours, RGB,
FilledContours, Path, Polygons, Shape, Dataset,
Contours, TriMesh, Graph, Nodes, EdgePaths, QuadMesh,
VectorField)
VectorField, Labels, HexTiles)


class GeoConversion(ElementConversion):
Expand Down
23 changes: 22 additions & 1 deletion geoviews/element/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
Contours as HvContours, Graph as HvGraph, Image as HvImage,
Nodes as HvNodes, Path as HvPath, Polygons as HvPolygons,
RGB as HvRGB, Text as HvText, TriMesh as HvTriMesh,
QuadMesh as HvQuadMesh, Points as HvPoints, VectorField as HvVectorField)
QuadMesh as HvQuadMesh, Points as HvPoints,
VectorField as HvVectorField, HexTiles as HvHexTiles,
Labels as HvLabels)

from shapely.geometry.base import BaseGeometry

Expand Down Expand Up @@ -192,6 +194,25 @@ class Points(_Element, HvPoints):
group = param.String(default='Points')


class HexTiles(_Element, HvHexTiles):
"""
Points represent a collection of points with
an associated cartopy coordinate-reference system.
"""

group = param.String(default='HexTiles')



class Labels(_Element, HvLabels):
"""
Points represent a collection of points with
an associated cartopy coordinate-reference system.
"""

group = param.String(default='Labels')


class VectorField(_Element, HvVectorField):
"""
A VectorField contains is a collection of vectors where each
Expand Down
5 changes: 3 additions & 2 deletions geoviews/operation/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from shapely.geometry import Polygon, LineString

from ..element import (Image, Shape, Polygons, Path, Points, Contours,
RGB, Graph, Nodes, EdgePaths, QuadMesh, VectorField)
RGB, Graph, Nodes, EdgePaths, QuadMesh, VectorField,
HexTiles, Labels)
from ..util import project_extents, geom_to_array


Expand Down Expand Up @@ -81,7 +82,7 @@ def _process_element(self, element):

class project_points(_project_operation):

supported_types = [Points, Nodes, VectorField]
supported_types = [Points, Nodes, VectorField, HexTiles, Labels]

def _process_element(self, element):
if not len(element):
Expand Down
34 changes: 31 additions & 3 deletions geoviews/plotting/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

from holoviews import Store, Overlay, NdOverlay
from holoviews.core import util
from holoviews.core.options import SkipRendering, Options
from holoviews.plotting.bokeh.annotation import TextPlot
from holoviews.core.options import SkipRendering, Options, Compositor
from holoviews.plotting.bokeh.annotation import TextPlot, LabelsPlot
from holoviews.plotting.bokeh.chart import PointPlot, VectorFieldPlot
from holoviews.plotting.bokeh.graphs import TriMeshPlot, GraphPlot
from holoviews.plotting.bokeh.hex_tiles import hex_binning, HexTilesPlot
from holoviews.plotting.bokeh.path import PolygonPlot, PathPlot, ContourPlot
from holoviews.plotting.bokeh.raster import RasterPlot, RGBPlot, QuadMeshPlot
from holoviews.plotting.bokeh.util import mpl_to_bokeh

from ...element import (WMTS, Points, Polygons, Path, Contours, Shape,
Image, Feature, Text, RGB, Nodes, EdgePaths,
Graph, TriMesh, QuadMesh, VectorField)
Graph, TriMesh, QuadMesh, VectorField, Labels,
HexTiles)
from ...operation import (project_image, project_shape, project_points,
project_path, project_graph, project_quadmesh)
from ...util import geom_to_array
Expand Down Expand Up @@ -206,9 +208,34 @@ def get_extents(self, element, ranges=None):
return None, None, None, None


class GeoLabelsPlot(GeoPlot, LabelsPlot):

_project_operation = project_points


class geo_hex_binning(hex_binning, project_points):
"""
Applies hex binning by computing aggregates on a hexagonal grid.

Should not be user facing as the returned element is not directly
useable.
"""

def _process(self, element, key=None):
if isinstance(element, HexTiles):
element = project_points._process(self, element)
return hex_binning._process(self, element)

compositor = Compositor(
"HexTiles", geo_hex_binning, None, 'data', output_type=HexTiles,
transfer_options=True, transfer_parameters=True, backends=['bokeh']
)
Compositor.register(compositor)


Store.register({WMTS: TilePlot,
Points: GeoPointPlot,
Labels: GeoLabelsPlot,
VectorField: GeoVectorFieldPlot,
Polygons: GeoPolygonPlot,
Contours: GeoContourPlot,
Expand All @@ -217,6 +244,7 @@ def get_extents(self, element, ranges=None):
Image: GeoRasterPlot,
RGB: GeoRGBPlot,
Feature: FeaturePlot,
HexTiles: HexTilesPlot,
Text: GeoTextPlot,
Overlay: OverlayPlot,
NdOverlay: OverlayPlot,
Expand Down
28 changes: 26 additions & 2 deletions geoviews/plotting/mpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
OverlayPlot as HvOverlayPlot,
PathPlot, PolygonPlot, RasterPlot,
ContourPlot, GraphPlot, TriMeshPlot,
QuadMeshPlot, VectorFieldPlot)
QuadMeshPlot, VectorFieldPlot,
HexTilesPlot, LabelsPlot)
from holoviews.plotting.mpl.util import get_raster_array


from ...element import (Image, Points, Feature, WMTS, Tiles, Text,
LineContours, FilledContours, is_geographic,
Path, Polygons, Shape, RGB, Contours, Nodes,
EdgePaths, Graph, TriMesh, QuadMesh, VectorField)
EdgePaths, Graph, TriMesh, QuadMesh, VectorField,
HexTiles, Labels)
from ...util import project_extents, geo_mesh

from ...operation import project_points, project_path, project_graph, project_quadmesh
Expand Down Expand Up @@ -317,6 +319,26 @@ class GeoPointPlot(GeoPlot, PointPlot):
_project_operation = project_points


class GeoLabelsPlot(GeoPlot, LabelsPlot):
"""
Draws a scatter plot from the data in a Labels Element.
"""

apply_ranges = param.Boolean(default=True)

_project_operation = project_points


class GeoHexTilesPlot(GeoPlot, HexTilesPlot):
"""
Draws a scatter plot from the data in a Points Element.
"""

apply_ranges = param.Boolean(default=True)

_project_operation = project_points


class GeoVectorFieldPlot(GeoPlot, VectorFieldPlot):
"""
Draws a vector field plot from the data in a VectorField Element.
Expand Down Expand Up @@ -517,6 +539,7 @@ def draw_annotation(self, axis, data, crs, opts):
WMTS: WMTSPlot,
Tiles: WMTSPlot,
Points: GeoPointPlot,
Labels: GeoLabelsPlot,
VectorField: GeoVectorFieldPlot,
Text: GeoTextPlot,
Layout: LayoutPlot,
Expand All @@ -531,6 +554,7 @@ def draw_annotation(self, axis, data, crs, opts):
TriMesh: GeoTriMeshPlot,
Nodes: GeoPointPlot,
EdgePaths: GeoPathPlot,
HexTiles: GeoHexTilesPlot,
QuadMesh: GeoQuadMeshPlot}, 'matplotlib')


Expand Down