Line glyph on GMapPlot

Good afternoon, I have been attempting to create a bounding box for a region on a GMapPlot using minima and maxima of a geographical location. For example, if I wanted to create a bounding box of the island of Oahu, I would take the minima and maxima of lat, long coordinate pairs and outline the island in red. I have the following code snippet to illustrate this. The code yields no errors but does not create a bounding box.

from future import print_function

from bokeh.plotting import *

from bokeh import session

import os.path

import pandas as pd

from bokeh.models.glyphs import Circle, Line

from bokeh.models import(

GMapPlot, Range1d, ColumnDataSource, LinearAxis,

PanTool, WheelZoomTool, BoxZoomTool, ResetTool, ResizeTool, BoxSelectTool, HoverTool,

BoxSelectionOverlay, GMapOptions,

NumeralTickFormatter, PrintfTickFormatter)

from bokeh.resources import INLINE

output_notebook()

‘’’
code omitted that creates a 1 row dataframe called “row” from survey data for the sake of anonymity. Similarly the title and
actual gps points of the map have been changed.
‘’’

x_range = Range1d()

y_range = Range1d()

map_options = GMapOptions(lat= 21.28, lng=157.59, zoom=11)

plot = GMapPlot(

x_range = x_range,

y_range = y_range,

map_options=map_options,

title = “Oahu”

)

plot.map_options.map_type=“terrain”

source = ColumnDataSource(

data=dict(

x=[row[“gps_lat_min”],row[“gps_lat_max”],row[“gps_lat_max”],row[“gps_lat_min”]],

y=[row[“gps_lon_min”],row[“gps_lon_min”],row[“gps_lon_max”],row[“gps_lon_max”]]

)

)
#line width has been replaced with .02 and .5, neither of which yield results

line = Line(x=“x”,y=“y”, line_color = “red”, line_width=.5)

plot.add_glyph(source, line)

pan = PanTool()

wheel_zoom = WheelZoomTool()

box_zoom = BoxZoomTool()

plot.add_tools(pan, wheel_zoom, box_zoom, )

xaxis = LinearAxis(axis_label=“lon.”, major_tick_in=0)

plot.add_layout(xaxis, ‘below’)

yaxis = LinearAxis(axis_label=“lat.”, major_tick_in=0)

plot.add_layout(yaxis, ‘left’)

show(plot)

``

``

Is there a better way to accomplish what I am attempting? Thank you for your assistance. I am sorry if this does not suffice as a minimum working example.

Hi,

You should be able to draw any glyph over a GMapPlot. I think the reason the bounding box (that you are creating with a line glyph) is not showing is in your data. Maybe the data type? Or data precision?

Also, it may be easier to use Patch or other glyphs instead of line? (just guessing…)

Finally, here’s a working example of circles and lines being drawn on your example:

from future import print_function

from bokeh.plotting import *

from bokeh import session

import os.path

import pandas as pd

from bokeh.models.glyphs import Circle, Line

from bokeh.models import(

GMapPlot, Range1d, ColumnDataSource, LinearAxis,

PanTool, WheelZoomTool, BoxZoomTool, ResetTool, ResizeTool, BoxSelectTool, HoverTool,

BoxSelectionOverlay, GMapOptions,

NumeralTickFormatter, PrintfTickFormatter)

from bokeh.resources import INLINE

output_file(‘test.html’)

x_range = Range1d()

y_range = Range1d()

map_options = GMapOptions(lat= 21.28, lng=157.59, zoom=11)

plot = GMapPlot(

x_range = x_range,

y_range = y_range,

map_options=map_options,

title = “Oahu”

)

plot.map_options.map_type=“terrain”

source = ColumnDataSource(

data=dict(

lat=[21.2890, 21.2705, 21.2869],

lon=[157.6194, 157.5700, 157.5905],

fill=[‘orange’, ‘blue’, ‘green’]

)

)

#line width has been replaced with .02 and .5, neither of which yield results

circle = Circle(x=“lon”, y=“lat”, size=15, fill_color=“fill”, line_color=“black”)

plot.add_glyph(source, circle)

circle = Line(x=“lon”, y=“lat”, line_color=“black”)

plot.add_glyph(source, circle)

pan = PanTool()

wheel_zoom = WheelZoomTool()

box_zoom = BoxZoomTool()

plot.add_tools(pan, wheel_zoom, box_zoom, )

xaxis = LinearAxis(axis_label=“lat”, major_tick_in=0, formatter=NumeralTickFormatter(format=“0.000”))

plot.add_layout(xaxis, ‘below’)

yaxis = LinearAxis(axis_label=“lon”, major_tick_in=0, formatter=PrintfTickFormatter(format=“%.3f”))

plot.add_layout(yaxis, ‘left’)

show(plot)

``

Cheers

Fabio

···

On Tuesday, August 4, 2015 at 12:03:08 AM UTC+2, [email protected] wrote:

Good afternoon, I have been attempting to create a bounding box for a region on a GMapPlot using minima and maxima of a geographical location. For example, if I wanted to create a bounding box of the island of Oahu, I would take the minima and maxima of lat, long coordinate pairs and outline the island in red. I have the following code snippet to illustrate this. The code yields no errors but does not create a bounding box.

from future import print_function

from bokeh.plotting import *

from bokeh import session

import os.path

import pandas as pd

from bokeh.models.glyphs import Circle, Line

from bokeh.models import(

GMapPlot, Range1d, ColumnDataSource, LinearAxis,

PanTool, WheelZoomTool, BoxZoomTool, ResetTool, ResizeTool, BoxSelectTool, HoverTool,

BoxSelectionOverlay, GMapOptions,

NumeralTickFormatter, PrintfTickFormatter)

from bokeh.resources import INLINE

output_notebook()

‘’’
code omitted that creates a 1 row dataframe called “row” from survey data for the sake of anonymity. Similarly the title and
actual gps points of the map have been changed.
‘’’

x_range = Range1d()

y_range = Range1d()

map_options = GMapOptions(lat= 21.28, lng=157.59, zoom=11)

plot = GMapPlot(

x_range = x_range,

y_range = y_range,

map_options=map_options,

title = “Oahu”

)

plot.map_options.map_type=“terrain”

source = ColumnDataSource(

data=dict(

x=[row[“gps_lat_min”],row[“gps_lat_max”],row[“gps_lat_max”],row[“gps_lat_min”]],

y=[row[“gps_lon_min”],row[“gps_lon_min”],row[“gps_lon_max”],row[“gps_lon_max”]]

)

)
#line width has been replaced with .02 and .5, neither of which yield results

line = Line(x=“x”,y=“y”, line_color = “red”, line_width=.5)

plot.add_glyph(source, line)

pan = PanTool()

wheel_zoom = WheelZoomTool()

box_zoom = BoxZoomTool()

plot.add_tools(pan, wheel_zoom, box_zoom, )

xaxis = LinearAxis(axis_label=“lon.”, major_tick_in=0)

plot.add_layout(xaxis, ‘below’)

yaxis = LinearAxis(axis_label=“lat.”, major_tick_in=0)

plot.add_layout(yaxis, ‘left’)

show(plot)

``

``

Is there a better way to accomplish what I am attempting? Thank you for your assistance. I am sorry if this does not suffice as a minimum working example.

Thank you Fabio, it turns out the the data type I was trying to use was a pandas Series with a single element.

···

On Monday, August 3, 2015 at 3:03:08 PM UTC-7, [email protected] wrote:

Good afternoon, I have been attempting to create a bounding box for a region on a GMapPlot using minima and maxima of a geographical location. For example, if I wanted to create a bounding box of the island of Oahu, I would take the minima and maxima of lat, long coordinate pairs and outline the island in red. I have the following code snippet to illustrate this. The code yields no errors but does not create a bounding box.

from future import print_function

from bokeh.plotting import *

from bokeh import session

import os.path

import pandas as pd

from bokeh.models.glyphs import Circle, Line

from bokeh.models import(

GMapPlot, Range1d, ColumnDataSource, LinearAxis,

PanTool, WheelZoomTool, BoxZoomTool, ResetTool, ResizeTool, BoxSelectTool, HoverTool,

BoxSelectionOverlay, GMapOptions,

NumeralTickFormatter, PrintfTickFormatter)

from bokeh.resources import INLINE

output_notebook()

‘’’
code omitted that creates a 1 row dataframe called “row” from survey data for the sake of anonymity. Similarly the title and
actual gps points of the map have been changed.
‘’’

x_range = Range1d()

y_range = Range1d()

map_options = GMapOptions(lat= 21.28, lng=157.59, zoom=11)

plot = GMapPlot(

x_range = x_range,

y_range = y_range,

map_options=map_options,

title = “Oahu”

)

plot.map_options.map_type=“terrain”

source = ColumnDataSource(

data=dict(

x=[row[“gps_lat_min”],row[“gps_lat_max”],row[“gps_lat_max”],row[“gps_lat_min”]],

y=[row[“gps_lon_min”],row[“gps_lon_min”],row[“gps_lon_max”],row[“gps_lon_max”]]

)

)
#line width has been replaced with .02 and .5, neither of which yield results

line = Line(x=“x”,y=“y”, line_color = “red”, line_width=.5)

plot.add_glyph(source, line)

pan = PanTool()

wheel_zoom = WheelZoomTool()

box_zoom = BoxZoomTool()

plot.add_tools(pan, wheel_zoom, box_zoom, )

xaxis = LinearAxis(axis_label=“lon.”, major_tick_in=0)

plot.add_layout(xaxis, ‘below’)

yaxis = LinearAxis(axis_label=“lat.”, major_tick_in=0)

plot.add_layout(yaxis, ‘left’)

show(plot)

``

``

Is there a better way to accomplish what I am attempting? Thank you for your assistance. I am sorry if this does not suffice as a minimum working example.