{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Street network figure-ground diagrams\n", "\n", "Author: [Geoff Boeing](https://geoffboeing.com/)\n", "\n", "Use OSMnx to download square-mile city street networks and visualize them as figure-ground diagrams. Discussed in this [blog post](http://geoffboeing.com/2017/01/square-mile-street-network-visualization/).\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 osmnx as ox\n", "from IPython.display import Image\n", "\n", "%matplotlib inline\n", "ox.__version__" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# configure the inline image display\n", "img_folder = \"images\"\n", "extension = \"png\"\n", "size = 240\n", "dpi = 40" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part I: create diagrams by passing in lat-long points" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"sf\"\n", "point = (37.793897, -122.402189)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point, filepath=fp, dpi=dpi, save=True, show=False, close=True\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"portland\"\n", "point = (45.517309, -122.682138)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"irvine\"\n", "point = (33.694981, -117.841375)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"rome\"\n", "point = (41.901336, 12.471831)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"all\",\n", " default_width=3.3,\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"barcelona-gothic\"\n", "point = (41.382850, 2.174192)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"all\",\n", " default_width=3.3,\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"nyc\"\n", "point = (40.757920, -73.983393)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point, filepath=fp, dpi=dpi, save=True, show=False, close=True\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"los-angeles\"\n", "point = (34.047404, -118.253146)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"paris\"\n", "point = (48.873702, 2.294136)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"drive\",\n", " default_width=3.3,\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"dc\"\n", "point = (38.907919, -77.036552)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"dubai1\"\n", "point = (25.203143, 55.270007)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"dubai2\"\n", "point = (25.056565, 55.207924)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"shanghai\"\n", "point = (31.234696, 121.481170)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"osaka\"\n", "point = (34.694834, 135.484761)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"drive\",\n", " default_width=2,\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"boston\"\n", "point = (42.362084, -71.057267)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"drive\",\n", " default_width=3.3,\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"sacramento\"\n", "point = (38.587193, -121.372872)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " network_type=\"drive\",\n", " default_width=5,\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part II: Create diagrams for any city, by just passing in a place name" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"Atlanta, Georgia, USA\"\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " address=place,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"Denver, Colorado, USA\"\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " address=place,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"Sao Chingcha, Bangkok, Thailand\"\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " address=place,\n", " network_type=\"drive\",\n", " default_width=2,\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"Medina of Tunis, Tunisia\"\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " address=place,\n", " network_type=\"all\",\n", " default_width=3,\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"Times Square, New York, NY, USA\"\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " address=place,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"East Village, New York, NY, USA\"\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " address=place,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "place = \"Charlotte, North Carolina, USA\"\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " address=place,\n", " network_type=\"drive\",\n", " filepath=fp,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part III: Configure street width pixels\n", "\n", "OSMnx uses the `highway` OSM tag to ascribe street widths, in pixels. You can pass in a dictionary of street widths to override the default values. Any street type that does not appear as a key in the street widths dict falls back onto the `default_width` value." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "street_widths = {\n", " \"footway\": 0.5,\n", " \"steps\": 0.5,\n", " \"pedestrian\": 0.5,\n", " \"path\": 0.5,\n", " \"track\": 0.5,\n", " \"service\": 2,\n", " \"residential\": 3,\n", " \"primary\": 5,\n", " \"motorway\": 6,\n", "}\n", "place = \"sf-custom\"\n", "point = (37.793897, -122.402189)\n", "fp = f\"./{img_folder}/{place}.{extension}\"\n", "fig, ax = ox.plot_figure_ground(\n", " point=point,\n", " filepath=fp,\n", " network_type=\"all\",\n", " street_widths=street_widths,\n", " dpi=dpi,\n", " save=True,\n", " show=False,\n", " close=True,\n", ")\n", "Image(fp, height=size, width=size)" ] }, { "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.10.8" } }, "nbformat": 4, "nbformat_minor": 4 }