├── .env ├── .gitignore ├── LICENSE ├── README.md ├── data └── README.md ├── img ├── BostonGraphViz.png ├── README.md ├── address_routing.png ├── codespaces.png ├── data_model.png ├── data_model_addresses.png ├── path_finding.png └── video.png ├── notebooks ├── 00-setup.ipynb └── 01-import.ipynb ├── poetry.lock ├── pyproject.toml └── web ├── address_routing.html └── osm_routing.html /.env: -------------------------------------------------------------------------------- 1 | NEO4J_URI=bolt://localhost:7687 2 | NEO4J_USER=neo4j 3 | NEO4J_PASSWORD=letmeinnow 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 William Lyon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Build A Routing Web Application With OpenStreetMap, Neo4j, & Leaflet.js 2 | 3 | ![](img/BostonGraphViz.png) 4 | 5 | * Slides: [dev.neo4j.com/routing-workshop](https://dev.neo4j.com/routing-workshop) 6 | * Tutorial: [Published On Medium here](https://medium.com/neo4j/build-a-routing-web-app-with-neo4j-openstreetmap-and-leaflet-js-bdc66443132c) 7 | * Video: [Workshop recording](https://www.youtube.com/watch?v=Z4XZgsbaD9c) 8 | 9 | [![Build a routing web application with openstreetmap, neo4j, and leaflet.js](img/video.png)](https://www.youtube.com/watch?v=Z4XZgsbaD9c) 10 | 11 | Using GitHub Codespaces is the recommended way to create a Python development environment for this workshop. 12 | 13 | ![](img/codespaces.png) 14 | 15 | ## Step 1: OpenStreetMap Data Import With OSMNx 16 | 17 | ![](img/data_model_addresses.png) 18 | 19 | First, create a [Neo4j AuraDB instance](https://dev.neo4j.com/aura). 20 | 21 | Then use [this notebook](https://github.com/johnymontana/openstreetmap-routing-web-app-workshop/blob/main/notebooks/01-import.ipynb) to import OpenStreetMap and address data into your Neo4j instance. 22 | 23 | 24 | ## Step 2: Leaflet.js Web Map 25 | 26 | ![](img/address_routing.png) 27 | 28 | [This file](https://github.com/johnymontana/openstreetmap-routing-web-app-workshop/blob/main/web/address_routing.html) contains HTML and JavaScript for a simple address search and routing web app. Edit the file to connect to your Neo4j AuraDB instance. 29 | 30 | We're using Dijkstra's algorithm for routing - can you improve the routing query using the A* algorithm? 31 | 32 | ![](img/path_finding.png) 33 | 34 | 35 | ## Setup 36 | 37 | This project uses Poetry to manage dependencies and python virtual environments. After cloning this repository, be sure [Poetry is installed](https://python-poetry.org/) then run: 38 | 39 | ``` 40 | poetry install 41 | ``` 42 | 43 | To add dependecies: 44 | 45 | ``` 46 | poetry add foobar 47 | ``` 48 | 49 | Update `.env` with any relevant environment variables, then to start Jupyter: 50 | 51 | ``` 52 | poetry shell 53 | jupyter notebook 54 | ``` 55 | -------------------------------------------------------------------------------- /data/README.md: -------------------------------------------------------------------------------- 1 | # data 2 | 3 | Placeholder directory for data files. 4 | -------------------------------------------------------------------------------- /img/BostonGraphViz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnymontana/openstreetmap-routing-web-app-workshop/a0c31488ba40f25a1d8850bf4d97fcabb2902cb3/img/BostonGraphViz.png -------------------------------------------------------------------------------- /img/README.md: -------------------------------------------------------------------------------- 1 | # img 2 | 3 | Placeholder directory for images. 4 | -------------------------------------------------------------------------------- /img/address_routing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnymontana/openstreetmap-routing-web-app-workshop/a0c31488ba40f25a1d8850bf4d97fcabb2902cb3/img/address_routing.png -------------------------------------------------------------------------------- /img/codespaces.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnymontana/openstreetmap-routing-web-app-workshop/a0c31488ba40f25a1d8850bf4d97fcabb2902cb3/img/codespaces.png -------------------------------------------------------------------------------- /img/data_model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnymontana/openstreetmap-routing-web-app-workshop/a0c31488ba40f25a1d8850bf4d97fcabb2902cb3/img/data_model.png -------------------------------------------------------------------------------- /img/data_model_addresses.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnymontana/openstreetmap-routing-web-app-workshop/a0c31488ba40f25a1d8850bf4d97fcabb2902cb3/img/data_model_addresses.png -------------------------------------------------------------------------------- /img/path_finding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnymontana/openstreetmap-routing-web-app-workshop/a0c31488ba40f25a1d8850bf4d97fcabb2902cb3/img/path_finding.png -------------------------------------------------------------------------------- /img/video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnymontana/openstreetmap-routing-web-app-workshop/a0c31488ba40f25a1d8850bf4d97fcabb2902cb3/img/video.png -------------------------------------------------------------------------------- /notebooks/00-setup.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "319c2edf", 6 | "metadata": { 7 | "tags": [] 8 | }, 9 | "source": [ 10 | "# `00-setup` Notebook\n", 11 | "\n", 12 | "Notebooks are numbered in the order they should be run (for data import projects) or according to a table of contents:\n", 13 | "\n", 14 | "* `00-setup` - initial environment setup and proof of concept\n", 15 | "* `01-explore` - exploratory data analysis" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 5, 21 | "id": "7864c9f1-cb72-462b-b0c4-a30432ecc78b", 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "# Uncomment below to install dependencies (optional)\n", 26 | "\n", 27 | "# pip install neo4j" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 1, 33 | "id": "b752ab4b", 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "import neo4j" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 2, 43 | "id": "cd911ca5", 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "NEO4J_URI = \"\"\n", 48 | "NEO4J_USER = \"neo4j\"\n", 49 | "NEO4J_PASSWORD = \"\"\n", 50 | "\n", 51 | "driver = neo4j.GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASSWORD))" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 3, 57 | "id": "d35abecb-0efe-4d97-b0c7-8042223c2f9a", 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "CYPHER_QUERY = \"\"\"\n", 62 | "MATCH (n) RETURN COUNT(n) AS node_count\n", 63 | "\"\"\"" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 14, 69 | "id": "8aed2b0a-dce7-4632-b184-eaf990df7497", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "def get_node_count(tx):\n", 74 | " results = tx.run(CYPHER_QUERY)\n", 75 | " df = results.to_df()\n", 76 | " return df" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 15, 82 | "id": "7a955ee5-f256-409c-95ae-a61661d08fb7", 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "with driver.session() as session:\n", 87 | " df = session.execute_read(get_node_count)" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 16, 93 | "id": "1760fa02-57a3-4850-9121-61543a42d5a9", 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "data": { 98 | "text/html": [ 99 | "
\n", 100 | "\n", 113 | "\n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | "
node_count
00
\n", 127 | "
" 128 | ], 129 | "text/plain": [ 130 | " node_count\n", 131 | "0 0" 132 | ] 133 | }, 134 | "execution_count": 16, 135 | "metadata": {}, 136 | "output_type": "execute_result" 137 | } 138 | ], 139 | "source": [ 140 | "df" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": null, 146 | "id": "c35dea36-f506-4e8e-a76f-93fcae29347f", 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [] 150 | } 151 | ], 152 | "metadata": { 153 | "kernelspec": { 154 | "display_name": "Python 3 (ipykernel)", 155 | "language": "python", 156 | "name": "python3" 157 | }, 158 | "language_info": { 159 | "codemirror_mode": { 160 | "name": "ipython", 161 | "version": 3 162 | }, 163 | "file_extension": ".py", 164 | "mimetype": "text/x-python", 165 | "name": "python", 166 | "nbconvert_exporter": "python", 167 | "pygments_lexer": "ipython3", 168 | "version": "3.9.13" 169 | } 170 | }, 171 | "nbformat": 4, 172 | "nbformat_minor": 5 173 | } 174 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "python-notebook-template" 3 | version = "0.1.0" 4 | description = "A template project for working with Python Jupyter notebooks." 5 | authors = ["William Lyon"] 6 | license = "MIT" 7 | readme = "README.md" 8 | packages = [{include = "python_notebook_template"}] 9 | 10 | [tool.poetry.dependencies] 11 | python = "^3.9" 12 | jupyter = "^1.0.0" 13 | neo4j = "^5.6.0" 14 | osmnx = "^1.3.0" 15 | 16 | [tool.poetry.group.dev.dependencies] 17 | poetry-dotenv-plugin = "^0.1.0" 18 | 19 | [build-system] 20 | requires = ["poetry-core"] 21 | build-backend = "poetry.core.masonry.api" 22 | -------------------------------------------------------------------------------- /web/address_routing.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | OpenStreetMap Routing With Neo4j 9 | 10 | 11 | 16 | 17 | 18 | 24 | 28 | 29 | 30 | 35 | 36 | 37 | 38 | 39 | 40 | 103 | 104 | 105 |
106 |
107 | 108 | 109 | 110 |
111 | 112 |
113 | 114 | 115 |
116 | 117 | 118 | 119 | 270 | 271 | 347 | 348 | -------------------------------------------------------------------------------- /web/osm_routing.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | OpenStreetMap Routing With Neo4j 12 | 13 | 14 | 19 | 20 | 21 | 27 | 31 | 32 | 33 | 38 | 39 | 40 | 41 | 42 | 43 | 54 | 55 | 56 | 57 |
58 | 59 | 60 | 148 | 149 | 150 | --------------------------------------------------------------------------------