Пример #1
0
 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
Пример #2
0
circle = Circle(x="lon",
                y="lat",
                size=15,
                fill_color="fill",
                line_color="black")
plot.add_glyph(source, circle)

pan = PanTool()
wheel_zoom = WheelZoomTool()
box_select = BoxSelectTool()

plot.add_tools(pan, wheel_zoom, box_select)

xformatter = MercatorTickFormatter(dimension="lon")
xticker = MercatorTicker(dimension="lon")
xaxis = LinearAxis(formatter=xformatter, ticker=xticker)
plot.add_layout(xaxis, 'below')

yformatter = MercatorTickFormatter(dimension="lat")
yticker = MercatorTicker(dimension="lat")
yaxis = LinearAxis(formatter=yformatter, ticker=yticker)
plot.add_layout(yaxis, 'left')

doc = Document()
doc.add_root(plot)

if __name__ == "__main__":
    doc.validate()
    filename = "maps.html"
    with open(filename, "w") as f:
Пример #3
0
    def prepare_plot(self,
                     plot_width=700,
                     plot_height=None,
                     zoom=None,
                     map_type='carto_light',
                     title=None,
                     **kwargs):
        """
        Create the actual plot object (stored in `self.plot`).
        
        Parameters:
        
        plot_width (int): desired plot width, in pixels
        plot_height (int): desired plot height, will be calculated 
            automatically if not supplied
        zoom (int): zoom factor for Google Maps, will be calculated 
            automatically if not supplied
        map_type (string): 'satellite', 'roadmap', or 'hybrid'
        title (string or tuple): if string, title is added to plot; 
            if tuple, the first value is the title, and second value 
            is a dict of kwargs
        kwargs: any options passed to Bokeh GMapPlot (title, etc.)
        
        """

        self._validate_workflow('prepare_plot')

        zoom_level, lat_center, lng_center, auto_plot_height = gmaps_utils.estimate_zoom(
            plot_width,
            x_bounds=(self.xmin, self.xmax),
            y_bounds=(self.ymin, self.ymax))
        if plot_height is None:
            plot_height = auto_plot_height

        if zoom is None:
            zoom = zoom_level

        if title is not None:
            if isinstance(title, str):
                title = Title(text=title)
            if isinstance(title, (list, tuple)):
                title, title_kwargs = title
                title = Title(text=title, **title_kwargs)

        if map_type in ('satellite', 'roadmap', 'terrain', 'hybrid'):
            if self.api_key is None:
                raise ValueError(
                    'Class must be instantiated with Google Maps API key to use map_type `{}`'
                    .format(map_type))

            map_options = GMapOptions(lat=lat_center,
                                      lng=lng_center,
                                      map_type=map_type,
                                      zoom=zoom)
            self.plot = GMapPlot(x_range=Range1d(),
                                 y_range=Range1d(),
                                 map_options=map_options,
                                 plot_width=plot_width,
                                 plot_height=plot_height,
                                 title=title,
                                 **kwargs)
            self.plot.api_key = self.api_key
            self.plot.add_tools(WheelZoomTool(), ResetTool(), PanTool(),
                                TapTool())
        elif map_type in bokeh_utils.get_tile_source(None):
            x_rng, y_rng = self.xmax - self.xmin, self.ymax - self.ymin
            x_range = Range1d(start=coordinate_utils.coord_to_webmercator(
                self.xmin - (x_rng * self.padding),
                precision=self.precision,
                longitude=True),
                              end=coordinate_utils.coord_to_webmercator(
                                  self.xmax + (x_rng * self.padding),
                                  precision=self.precision,
                                  longitude=True))
            y_range = Range1d(start=coordinate_utils.coord_to_webmercator(
                self.ymin - (y_rng * self.padding),
                precision=self.precision,
                longitude=False),
                              end=coordinate_utils.coord_to_webmercator(
                                  self.ymax + (y_rng * self.padding),
                                  precision=self.precision,
                                  longitude=False))
            self.plot = Plot(x_range=x_range,
                             y_range=y_range,
                             frame_width=plot_width,
                             frame_height=plot_height,
                             title=title,
                             **kwargs)

            self.plot.add_tile(bokeh_utils.get_tile_source(map_type))
            self.plot.add_tools(WheelZoomTool(), ResetTool(), PanTool(),
                                TapTool())

            xformatter = MercatorTickFormatter(dimension="lon")
            xticker = MercatorTicker(dimension="lon")
            xaxis = LinearAxis(formatter=xformatter,
                               ticker=xticker,
                               axis_line_alpha=0.1,
                               minor_tick_line_alpha=0.1,
                               major_tick_line_alpha=0.1,
                               major_label_text_alpha=0.5)
            self.plot.add_layout(xaxis, 'below')

            yformatter = MercatorTickFormatter(dimension="lat")
            yticker = MercatorTicker(dimension="lat")
            yaxis = LinearAxis(formatter=yformatter,
                               ticker=yticker,
                               axis_line_alpha=0.1,
                               minor_tick_line_alpha=0.1,
                               major_tick_line_alpha=0.1,
                               major_label_text_alpha=0.5)
            self.plot.add_layout(yaxis, 'left')

        else:
            raise ValueError('Invalid map_type.')

        for source_label, source in self.sources.items():
            source = self._create_columndatasource(source)

            for widget_name in self.widgets.keys():
                widget_dict = self.widgets[widget_name]
                if widget_dict['source'] == source_label:
                    widget_dict['filter'].args['source'] = source
                    for callback_list in widget_dict[
                            'widget'].js_property_callbacks.values():
                        for callback in callback_list:
                            callback.args['source'] = source

            if source_label in self.views:
                self.views[source_label].source = source

            self.columndatasources[source_label] = source

        self.validation['prepare_plot'] = True

        return self
Пример #4
0
    def __init__(self,
                 coord_conv_object,
                 output_filename="path_planning.html",
                 debug=False):
        """
        Init method
        Input: optional debug parameter which toogles debug messages
        Output: none
        """
        self.debug = debug

        self.coord_conv = coord_conv_object

        # Set output file for Bokeh
        output_file(output_filename)

        # Set bounds for map plot
        use_bounds = False

        # range bounds supplied in web mercator coordinates
        if use_bounds:
            bounds_bottom_left_Geodetic = [54.5, 8]
            bounds_top_right_Geodetic = [58, 13]
            bounds_bottom_left_PseudoMercator = self.coord_conv.Geodetic2PseudoMercator(
                bounds_bottom_left_Geodetic)
            bounds_top_right_PseudoMercator = self.coord_conv.Geodetic2PseudoMercator(
                bounds_top_right_Geodetic)
            print colored(
                'Bottom left: lat: %d, lng: %d, x: %d, y: %d' %
                (bounds_bottom_left_Geodetic[0],
                 bounds_bottom_left_Geodetic[1],
                 bounds_bottom_left_PseudoMercator[0],
                 bounds_bottom_left_PseudoMercator[1]), 'yellow')
            print colored(
                '  Top right: lat: %d, lng: %d, x: %d, y: %d' %
                (bounds_top_right_Geodetic[0], bounds_top_right_Geodetic[1],
                 bounds_top_right_PseudoMercator[0],
                 bounds_top_right_PseudoMercator[1]), 'yellow')
            self.p = figure(
                x_range=(bounds_bottom_left_PseudoMercator[0],
                         bounds_top_right_PseudoMercator[0]),
                y_range=(bounds_bottom_left_PseudoMercator[1],
                         bounds_top_right_PseudoMercator[1]
                         ))  #, x_axis_type="mercator", y_axis_type="mercator")
        else:
            self.p = figure()
        # alternative way to add lat lng axis due to above commented method does not work, https://github.com/bokeh/bokeh/issues/6986
        self.p.xaxis[0].ticker = MercatorTicker(dimension='lon')
        self.p.yaxis[0].ticker = MercatorTicker(dimension='lat')
        self.p.xaxis[0].formatter = MercatorTickFormatter(dimension='lon')
        self.p.yaxis[0].formatter = MercatorTickFormatter(dimension='lat')
        self.p.add_tile(CARTODBPOSITRON)
        # Add axis labels to plot
        self.p.xaxis.axis_label = "Longitude [deg]"
        self.p.yaxis.axis_label = "Latitude [deg]"

        self.cur_path_color = 0
        self.path_end_colors = [
            'firebrick', 'seagreen', 'steelblue', 'fuchsia', 'magenta'
        ]
        self.path_colors = ['red', 'green', 'blue', 'deeppink', 'purple']