{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Working with graphs\n", "\n", "This notebook gives a few examples how Pyrosm can be used together with Python network analysis libraries. Before starting, ensure that you have read the [basic documentation about how to export graphs with Pyrosm](basics.html#export-street-networks-to-graph).\n", "\n", "**Contents**:\n", "\n", "1. [Find shortest path with `pyrosm + networkx + osmnx`](#find-shortest-path-with-pyrosm-networkx-osmnx)\n", "2. [Calculate the catchment areas of hospitals in Estonia with `pyrosm + igraph`](#calculate-the-catchment-areas-of-hospitals-in-estonia-with-pyrosm-igraph).\n", "3. [Calculate the job accessibility in Helsinki Region with `pyrosm + pandana`](#calculate-the-job-accessibility-in-helsinki-region-with-pyrosm-pandana)\n", "\n", "```{note}\n", "\n", "1. The idea of this page is not to give a comprehensive overview of all the possibilities that you can do with these network analysis libraries, but to just give you a bit of idea what can be done. You can get more detailed and further information from the documentation of the packages themselves. \n", "\n", "2. Integrating routing or network analysis functionalities is not planned for Pyrosm. There is a separate Python project called `cafein` that will be built on top of `pyrosm` including different routing and network analysis functionalities (*will become available in 2021*). \n", "\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Find shortest path with Pyrosm + NetworkX + OSMnx\n", "\n", "This tutorial shows how to construct simple shortest path routing between selected source and destination addresses using [NetworkX](https://networkx.org/documentation/stable/) and [OSMnx](https://github.com/gboeing/osmnx).\n", "Pyrosm is used for extracting the data from OSM PBF file and constructing the graph, while NetworkX provides the basic network analysis capabilities and OSMnx provides many useful functionalities that makes it easy to work with street networks." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | access | \n", "bicycle | \n", "bridge | \n", "cycleway | \n", "est_width | \n", "foot | \n", "footway | \n", "highway | \n", "int_ref | \n", "lanes | \n", "... | \n", "width | \n", "id | \n", "timestamp | \n", "version | \n", "tags | \n", "osm_type | \n", "geometry | \n", "u | \n", "v | \n", "length | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "unclassified | \n", "None | \n", "2 | \n", "... | \n", "None | \n", "4236349 | \n", "1380031970 | \n", "21 | \n", "{\"name:fi\":\"Erottajankatu\",\"name:sv\":\"Skillnad... | \n", "way | \n", "LINESTRING (24.94327 60.16651, 24.94337 60.16644) | \n", "1372477605 | \n", "292727220 | \n", "9.370 | \n", "
| 1 | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "unclassified | \n", "None | \n", "2 | \n", "... | \n", "None | \n", "4236349 | \n", "1380031970 | \n", "21 | \n", "{\"name:fi\":\"Erottajankatu\",\"name:sv\":\"Skillnad... | \n", "way | \n", "LINESTRING (24.94337 60.16644, 24.94340 60.16641) | \n", "292727220 | \n", "2394117042 | \n", "4.499 | \n", "
| 2 | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "unclassified | \n", "None | \n", "2 | \n", "... | \n", "None | \n", "4243035 | \n", "1543430213 | \n", "12 | \n", "{\"name:fi\":\"Korkeavuorenkatu\",\"name:sv\":\"H\\u00... | \n", "way | \n", "LINESTRING (24.94567 60.16767, 24.94567 60.16763) | \n", "296250563 | \n", "2049084195 | \n", "4.174 | \n", "
| 3 | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "unclassified | \n", "None | \n", "2 | \n", "... | \n", "None | \n", "4243035 | \n", "1543430213 | \n", "12 | \n", "{\"name:fi\":\"Korkeavuorenkatu\",\"name:sv\":\"H\\u00... | \n", "way | \n", "LINESTRING (24.94567 60.16763, 24.94569 60.16744) | \n", "2049084195 | \n", "60072359 | \n", "21.692 | \n", "
| 4 | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "None | \n", "unclassified | \n", "None | \n", "2 | \n", "... | \n", "None | \n", "4243035 | \n", "1543430213 | \n", "12 | \n", "{\"name:fi\":\"Korkeavuorenkatu\",\"name:sv\":\"H\\u00... | \n", "way | \n", "LINESTRING (24.94569 60.16744, 24.94571 60.16726) | \n", "60072359 | \n", "6100704327 | \n", "19.083 | \n", "
5 rows × 33 columns
\n", "| \n", " | 1 | \n", "2 | \n", "3 | \n", "4 | \n", "5 | \n", "
|---|---|---|---|---|---|
| 8094713890 | \n", "517.169983 | \n", "1408.347046 | \n", "1479.694946 | \n", "1656.630005 | \n", "1695.170044 | \n", "
| 1956624053 | \n", "520.372009 | \n", "1411.548950 | \n", "1482.896973 | \n", "1659.832031 | \n", "1698.371948 | \n", "
| 8094751564 | \n", "529.398010 | \n", "1420.574951 | \n", "1491.922974 | \n", "1668.858032 | \n", "1707.397949 | \n", "
| 8094751563 | \n", "537.838013 | \n", "1429.015015 | \n", "1500.363037 | \n", "1677.297974 | \n", "1715.838013 | \n", "
| 1956624064 | \n", "540.979004 | \n", "1432.156006 | \n", "1503.504028 | \n", "1680.438965 | \n", "1718.979004 | \n", "
| 223537823 | \n", "554.515991 | \n", "1445.692993 | \n", "1517.041016 | \n", "1693.975952 | \n", "1732.515991 | \n", "
| 8094751562 | \n", "550.070984 | \n", "1441.248047 | \n", "1512.595947 | \n", "1689.531006 | \n", "1728.071045 | \n", "
| 7747100203 | \n", "549.541992 | \n", "1440.718994 | \n", "1512.067017 | \n", "1689.001953 | \n", "1727.541992 | \n", "
| 8094751561 | \n", "549.187988 | \n", "1440.364990 | \n", "1511.713013 | \n", "1688.647949 | \n", "1727.187988 | \n", "
| 8094751560 | \n", "545.604004 | \n", "1436.781006 | \n", "1508.129028 | \n", "1685.063965 | \n", "1723.604004 | \n", "