{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Street network bearings\n", "\n", "Author: [Geoff Boeing](https://geoffboeing.com/)\n", "\n", "Calculate street network bearings and visualize the spatial orientation of a street network. See [this notebook](17-street-network-orientations.ipynb) for a superior example!\n", "\n", " - [Overview of OSMnx](http://geoffboeing.com/2016/11/osmnx-python-street-networks/)\n", " - [GitHub repo](https://github.com/gboeing/osmnx)\n", " - [Examples, demos, tutorials](https://github.com/gboeing/osmnx-examples)\n", " - [Documentation](https://osmnx.readthedocs.io/en/stable/)\n", " - [Journal article/citation](http://geoffboeing.com/publications/osmnx-complex-street-networks/)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import osmnx as ox\n", "import pandas as pd\n", "%matplotlib inline\n", "ox.config(log_console=True, use_cache=True)\n", "ox.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### First, look at a non-grid street network\n", "\n", "Orinda, California is a hilly suburb with winding loops and cul-de-sacs. We can see this lack of consistent orientation in its histogram of edge bearings." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "G = ox.graph_from_place('Orinda, California', network_type='drive')\n", "fig, ax = ox.plot_graph(ox.project_graph(G), node_size=0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# calculate edge bearings and visualize their frequency\n", "G = ox.add_edge_bearings(G)\n", "bearings = pd.Series([data['bearing'] for u, v, k, data in G.edges(keys=True, data=True)])\n", "ax = bearings.hist(bins=30, zorder=2, alpha=0.8)\n", "xlim = ax.set_xlim(0, 360)\n", "ax.set_title('Orinda street network edge bearings')\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# polar plot\n", "import numpy as np\n", "n = 30\n", "count, division = np.histogram(bearings, bins=[ang*360/n for ang in range(0,n+1)])\n", "division = division[0:-1]\n", "width = 2 * np.pi/n\n", "ax = plt.subplot(111, projection='polar')\n", "ax.set_theta_zero_location('N')\n", "ax.set_theta_direction('clockwise')\n", "bars = ax.bar(division * np.pi/180 - width * 0.5 , count, width=width, bottom=0.0)\n", "ax.set_title('Orinda street network edge bearings', y=1.1)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Now look at a gridded street network\n", "\n", "Santa Monica has an orthogonal grid characterized by four-way intersections. We can see this clear orientation in its histogram of edge bearings." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "G = ox.graph_from_place('Santa Monica, California', network_type='drive')\n", "fig, ax = ox.plot_graph(ox.project_graph(G), node_size=0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# calculate edge bearings and visualize their frequency\n", "G = ox.add_edge_bearings(G)\n", "bearings = pd.Series([data['bearing'] for u, v, k, data in G.edges(keys=True, data=True)])\n", "ax = bearings.hist(bins=30, zorder=2, alpha=0.8)\n", "ax.set_xlim(0, 360)\n", "ax.set_title('Santa Monica street network edge bearings')\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# polar plot\n", "n = 30\n", "count, division = np.histogram(bearings, bins=[ang*360/n for ang in range(0,n+1)])\n", "division = division[0:-1]\n", "width = 2 * np.pi/n\n", "ax = plt.subplot(111, projection='polar')\n", "ax.set_theta_zero_location('N')\n", "ax.set_theta_direction('clockwise')\n", "bars = ax.bar(division * np.pi/180 - width * 0.5 , count, width=width, bottom=20.0)\n", "ax.set_title('Santa Monica street network edge bearings', y=1.1)\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python (ox)", "language": "python", "name": "ox" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.1" } }, "nbformat": 4, "nbformat_minor": 4 }