{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pyproj\n", "import numpy as np\n", "import geoviews as gv\n", "import geoviews.feature as gf\n", "from bokeh.sampledata.airport_routes import airports, routes\n", "\n", "gv.extension('matplotlib')\n", "\n", "gv.output(fig='svg', size=250)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def get_circle_path(start, end, samples=200):\n", " sx, sy = start\n", " ex, ey = end\n", " g = pyproj.Geod(ellps='WGS84')\n", " (az12, az21, dist) = g.inv(sx, sy, ex, ey)\n", " lonlats = g.npts(sx, sy, ex, ey, samples)\n", " return np.array([(sx, sy)]+lonlats+[(ex, ey)])\n", "\n", "# Compute great-circle paths for all US flight routes from Honolulu\n", "paths = []\n", "honolulu = (-157.9219970703125, 21.318700790405273)\n", "routes = routes[routes.SourceID==3728]\n", "airports = airports[airports.AirportID.isin(list(routes.DestinationID)+[3728])]\n", "for i, route in routes.iterrows():\n", " airport = airports[airports.AirportID==route.DestinationID].iloc[0]\n", " paths.append(get_circle_path(honolulu, (airport.Longitude, airport.Latitude)))\n", "\n", "# Define Graph from Nodes and EdgePaths\n", "path = gv.EdgePaths(paths)\n", "points = gv.Nodes(airports, ['Longitude', 'Latitude', 'AirportID'], ['Name', 'City'])\n", "graph = gv.Graph((routes, points, path), ['SourceID', 'DestinationID'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gf.ocean * gf.land * gf.lakes * gf.coastline * graph.opts(\n", " node_color='black', node_size=8)" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }