From c6c5ce261aa725853e00094fbe59ff3650ad1e19 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Wed, 2 Nov 2016 03:15:13 +0000 Subject: [PATCH] Renamed ProjectImage and added project_shape --- geoviews/operation.py | 27 +++++++++++++++++++++++---- geoviews/plotting/bokeh/__init__.py | 4 ++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/geoviews/operation.py b/geoviews/operation.py index 56218ea8..4ae1b23a 100644 --- a/geoviews/operation.py +++ b/geoviews/operation.py @@ -5,12 +5,30 @@ from holoviews.operation import ElementOperation -from .element import Image - +from .element import Image, Shape, Shape, Polygons, Path from .util import project_extents +class project_shape(ElementOperation): + """ + Projects Shape, Polygons and Path Elements from their source + coordinate reference system to the supplied projection. + """ + + projection = param.ClassSelector(default=ccrs.GOOGLE_MERCATOR, + class_=ccrs.Projection, + instantiate=False, doc=""" + Projection the shape type is projected to.""") + + def _process_element(self, element): + geom = self.p.projection.project_geometry(element.geom(), + element.crs) + return element.clone(geom, crs=self.p.projection) + + def _process(self, element, key=None): + return element.map(self._process_element, [Shape, Polygons, Path]) + -class ProjectImage(ElementOperation): +class project_image(ElementOperation): """ Projects an geoviews Image to the specified projection, returning a regular HoloViews Image type. Works by @@ -19,7 +37,8 @@ class ProjectImage(ElementOperation): """ projection = param.ClassSelector(default=ccrs.GOOGLE_MERCATOR, - class_=ccrs.Projection, doc=""" + class_=ccrs.Projection, + instantiate=False, doc=""" Projection the image type is projected to.""") def _process(self, img, key=None): diff --git a/geoviews/plotting/bokeh/__init__.py b/geoviews/plotting/bokeh/__init__.py index 9bde302d..3736e554 100644 --- a/geoviews/plotting/bokeh/__init__.py +++ b/geoviews/plotting/bokeh/__init__.py @@ -20,7 +20,7 @@ from ...element import (WMTS, Points, Polygons, Path, Shape, Image, Feature, is_geographic, Text) -from ...operation import ProjectImage +from ...operation import project_image from ...util import project_extents, geom_to_array DEFAULT_PROJ = GOOGLE_MERCATOR @@ -98,7 +98,7 @@ class GeoRasterPlot(GeoPlot, RasterPlot): def get_data(self, element, ranges=None, empty=False): l, b, r, t = self.get_extents(element, ranges) if self.geographic: - element = ProjectImage(element, projection=DEFAULT_PROJ) + element = project_image(element, projection=DEFAULT_PROJ) img = element.dimension_values(2, flat=False) mapping = dict(image='image', x='x', y='y', dw='dw', dh='dh') if empty: