예제 #1
0
 def test_point_draw_callback_initialized_js(self):
     points = Points([(0, 1)])
     PointDraw(source=points)
     plot = bokeh_renderer.get_plot(points)
     cb = plot.callbacks[0].callbacks[0]
     self.assertEqual(plot.handles['source'].js_property_callbacks,
                      {'change:data': [cb], 'patching': [cb]})
예제 #2
0
def request_basemap_tiles(
        lon,
        lat,
        dx,
        dy,
        url='https://mt1.google.com/vt/lyrs=s&x={X}&y={Y}&z={Z}',
        utm=False):

    if utm == False:
        extents = (lon - dx, lat - dy, lon + dx, lat + dy)
        tiles = gv.WMTS(url, extents=extents)
        location = gv.Points([], vdims="vertices")
        point_stream = PointDraw(source=location)
        tiles = gv.WMTS(url, extents=extents)

        return tiles

    else:
        u = utm.from_latlon(lat, lon)
        utm_lon = u[0]
        utm_lat = u[1]
        utm_zone = u[2]
        utm_zone_code = u[3]

        extents = utm_lon - dx, utm_lat - dy, utm_lon + dx, utm_lat + dy
        tiles = gv.WMTS(url, extents=extents, crs=ccrs.UTM(utm_zone))

        return tiles, utm_zone
예제 #3
0
 def test_active_tools_draw_stream(self):
     scatter = Scatter([1, 2, 3]).options(active_tools=['point_draw'])
     PointDraw(source=scatter)
     plot = bokeh_renderer.get_plot(scatter)
     toolbar = plot.state.toolbar
     self.assertIsInstance(toolbar.active_tap, tools.PointDrawTool)
     self.assertIsInstance(toolbar.active_drag, tools.PointDrawTool)
예제 #4
0
 def test_point_draw_callback_initialize(self):
     points = Points([(0, 1)])
     point_draw = PointDraw(source=points)
     plot = bokeh_renderer.get_plot(points)
     self.assertIsInstance(plot.callbacks[0], PointDrawCallback)
     data = {'x': [0], 'y': [1]}
     self.assertEqual(point_draw.element, points)
예제 #5
0
 def __init__(self, polys=None, points=None, crs=None, **params):
     super(GeoAnnotator, self).__init__(**params)
     plot_opts = dict(height=self.height, width=self.width)
     self.tiles = WMTS(self.tile_url,
                       extents=self.extent,
                       crs=ccrs.PlateCarree()).opts(plot=plot_opts)
     polys = [] if polys is None else polys
     points = [] if points is None else points
     crs = ccrs.GOOGLE_MERCATOR if crs is None else crs
     tools = [CheckpointTool(), RestoreTool(), ClearTool()]
     opts = dict(tools=tools,
                 finalize_hooks=[initialize_tools],
                 color_index=None)
     if not isinstance(polys, Path):
         polys = self.path_type(polys, crs=crs).options(**opts)
     self.polys = polys.options(**opts)
     self.poly_stream = PolyDraw(source=self.polys,
                                 data={},
                                 show_vertices=True)
     self.vertex_stream = PolyEdit(source=self.polys)
     if isinstance(points, Points):
         self.points = points
     else:
         self.points = Points(points, self.polys.kdims,
                              crs=crs).options(**opts)
     self.point_stream = PointDraw(source=self.points, data={})
예제 #6
0
 def test_point_draw_callback_with_vdims(self):
     points = Points([(0, 1, 'A')], vdims=['A'])
     point_draw = PointDraw(source=points)
     plot = bokeh_server_renderer.get_plot(points)
     self.assertIsInstance(plot.callbacks[0], PointDrawCallback)
     callback = plot.callbacks[0]
     data = {'x': [1, 2, 3], 'y': [1, 2, 3], 'A': [None, None, 1]}
     callback.on_msg({'data': data})
     self.assertEqual(point_draw.element, Points(data, vdims=['A']))
예제 #7
0
 def test_point_draw_callback(self):
     points = Points([(0, 1)])
     point_draw = PointDraw(source=points)
     plot = bokeh_server_renderer.get_plot(points)
     self.assertIsInstance(plot.callbacks[0], PointDrawCallback)
     callback = plot.callbacks[0]
     data = {'x': [1, 2, 3], 'y': [1, 2, 3]}
     callback.on_msg({'data': data})
     self.assertEqual(point_draw.element, Points(data))
예제 #8
0
 def __init__(self, **params):
     super(PointAnnotator, self).__init__(**params)
     style = dict(editable=True)
     plot = dict(width=self.width, height=self.table_height)
     for col in self.point_columns:
         if col not in self.points:
             self.points = self.points.add_dimension(col, 0, None, True)
     self.point_stream = PointDraw(source=self.points, data={})
     self.point_table = Table(self.points).opts(plot=plot, style=style)
예제 #9
0
 def _init_points(self, points=None):
     opts = dict(tools=self._tools,
                 finalize_hooks=[initialize_tools],
                 color_index=None)
     points = self.points if points is None else points
     self.points = points.options(**opts)
     self.point_stream = PointDraw(source=self.points,
                                   drag=True,
                                   data={},
                                   num_objects=self.num_points)
예제 #10
0
 def _link_points(self):
     style = dict(editable=True)
     plot = dict(width=self.table_width, height=self.table_height)
     for col in self.point_columns:
         if col not in self.points:
             self.points = self.points.add_dimension(col, 0, None, True)
     self.point_stream = PointDraw(source=self.points, data={})
     projected = gv.project(self.points, projection=ccrs.PlateCarree())
     self.point_table = Table(projected).opts(plot=plot, style=style)
     self.point_link = PointTableLink(source=self.points,
                                      target=self.point_table)
예제 #11
0
 def test_point_draw_shared_datasource_callback(self):
     points = Points([1, 2, 3])
     table = Table(points.data, ['x', 'y'])
     layout = (points + table).options(shared_datasource=True, clone=False)
     PointDraw(source=points)
     self.assertIs(points.data, table.data)
     plot = bokeh_renderer.get_plot(layout)
     point_plot = plot.subplots[(0, 0)].subplots['main']
     table_plot = plot.subplots[(0, 1)].subplots['main']
     self.assertIs(point_plot.handles['source'],
                   table_plot.handles['source'])
예제 #12
0
 def __init__(self, polys=None, points=None, crs=None, **params):
     super(GeoAnnotator, self).__init__(**params)
     plot_opts = dict(height=self.height, width=self.width)
     self.tiles = WMTS(self.tile_url,
                       extents=self.extent,
                       crs=ccrs.PlateCarree()).opts(plot=plot_opts)
     polys = [] if polys is None else polys
     points = [] if points is None else points
     crs = ccrs.GOOGLE_MERCATOR if crs is None else crs
     self.polys = self.path_type(polys, crs=crs)
     self.poly_stream = PolyDraw(source=self.polys, data={})
     self.vertex_stream = PolyEdit(source=self.polys)
     self.points = Points(points, self.polys.kdims, crs=crs)
     self.point_stream = PointDraw(source=self.points, data={})
예제 #13
0
def pick_points_from_basemap_tiles(tiles, utm_zone=None):

    if utm_zone == None:
        location = gv.Points([], vdims="vertices")

    else:
        location = gv.Points([], vdims="vertices", crs=ccrs.UTM(utm_zone))

    point_stream = PointDraw(source=location)
    base_map = (tiles * location).opts(
        opts.Points(width=500,
                    height=500,
                    size=12,
                    color='black',
                    tools=["hover"]))
    app = pn.panel(base_map)
    return app, point_stream
예제 #14
0
 def test_point_draw_callback_with_vdims_initialization(self):
     points = Points([(0, 1, 'A')], vdims=['A'])
     stream = PointDraw(source=points)
     bokeh_server_renderer.get_plot(points)
     self.assertEqual(stream.element.dimension_values('A'), np.array(['A']))
예제 #15
0
 def test_point_draw_callback_initialized_server(self):
     points = Points([(0, 1)])
     PointDraw(source=points)
     plot = bokeh_server_renderer.get_plot(points)
     self.assertEqual(plot.handles['source']._callbacks,
                      {'data': [plot.callbacks[0].on_change]})
예제 #16
0
import geoviews as gv
import holoviews as hv
from holoviews.streams import (Params, PolyEdit, BoxEdit, PointDraw)
# from holoviews.operation.datashader import regrid
import panel as pp
# import param

hv.extension('bokeh')
# pp.extension()

tiles = gv.tile_sources.StamenTerrain().options(width=950, height=600)
tiles.extents = (-125, 25, -65, 50)
box_poly = gv.Polygons([]).options(fill_alpha=.2)
box_stream = BoxEdit(source=box_poly, num_objects=1, name="boxedit")
points = gv.Points([])
point_stream = PointDraw(source=points)

elevation_service = quest.util.ServiceSelector(
    parameter='elevation', default='svc://usgs-ned:1-arc-second')

# Explicitly create a panel widget
btn_download = pp.widgets.Button(name='Download & Fill', button_type='danger')
btn_download_stream = Params(btn_download, ['clicks'],
                             rename={'clicks': 'download_clicks'})

btn_run = pp.widgets.Button(name='Extract', button_type='danger')
btn_run_stream = Params(btn_run, ['clicks'], rename={'clicks': 'run_clicks'})

btn_delin = pp.widgets.Button(name='Delinate', button_type='danger')
btn_delin_stream = Params(btn_delin, ['clicks'],
                          rename={'clicks': 'delin_clicks'})