Routing street networks: Find your way with Python
Tutorial — Getting Direction routes with Python and route animations
We use routing services almost every day to get directions from one location to another. In this tutorial, we will learn how to make our routing animation to get from one place to another, using Python’s excellent libraries, OMSNx, Geopandas and Plotly Express.
Set up Network Graphs
First of all, we need to get the data for the location we want. So, let us download first and visualize street network data for a place. In this tutorial, I will use Stockholm, Sweden, as an example. Feel free to pick up any other locations.
First, let us import the necessary libraries.
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point, LineString
import plotly_express as px
import networkx as nx
import osmnx as ox
ox.config(use_cache=True, log_console=True)
We need to set up the network graphs. OSMNx has plenty of ways to get street networks from all over the world using the excellent opensource service of OpenStreetMap. I have created here a function that can generate a graph by providing addresses or coordinates.
def create_graph(loc, dist, transport_mode…