Great circle

In [1]:
import pyproj
import numpy as np
import geoviews as gv
import geoviews.feature as gf
from bokeh.sampledata.airport_routes import airports, routes

gv.extension('matplotlib')

gv.output(fig='svg', size=250)

Define data

In [2]:
def get_circle_path(start, end, samples=200):
    sx, sy = start
    ex, ey = end
    g = pyproj.Geod(ellps='WGS84')
    (az12, az21, dist) = g.inv(sx, sy, ex, ey)
    lonlats = g.npts(sx, sy, ex, ey, samples)
    return np.array([(sx, sy)]+lonlats+[(ex, ey)])

# Compute great-circle paths for all US flight routes from Honolulu
paths = []
honolulu = (-157.9219970703125, 21.318700790405273)
routes = routes[routes.SourceID==3728]
airports = airports[airports.AirportID.isin(list(routes.DestinationID)+[3728])]
for i, route in routes.iterrows():
    airport = airports[airports.AirportID==route.DestinationID].iloc[0]
    paths.append(get_circle_path(honolulu, (airport.Longitude, airport.Latitude)))

# Define Graph from Nodes and EdgePaths
path = gv.EdgePaths(paths)
points = gv.Nodes(airports, ['Longitude', 'Latitude', 'AirportID'], ['Name', 'City'])
graph = gv.Graph((routes, points, path), ['SourceID', 'DestinationID'])

Plot

In [3]:
gf.ocean * gf.land * gf.lakes * gf.coastline * graph.opts(
    node_color='black', node_size=8)
Out[3]:

Download this notebook from GitHub (right-click to download).