Adjust the OpenStreetMap Street Network Graph with NetworkX

Renee LIN
5 min readOct 2, 2023
https://bigdataschool.ru/blog/connected-components-in-directed-graph-with-networkx-in-colab.html

I have obtained a street network using a polygon, if you are interested in how to obtain the road network you want, you can check this post. I will check

0. Visualize the network and a bit of GeoDataframe

  1. Renaming the Nodes and Edges
  2. Accessing the neighbors/downstream roads, updating the neighbor info
  3. Validate the neighbor quantity

0. Visualize the network and a bit of GeoDataframe

import osmnx as ox
from shapely.geometry import Polygon

coords = [...see the complete coords at the end of this post]
poly = Polygon(coords)
graph = ox.graph_from_polygon(poly, network_type='drive',simplify=True)
ox.plot_graph(graph)

We can transform the network in the GeoDataframe using GeoPandas.

nodes, edges = ox.utils_graph.graph_to_gdfs(graph)

--

--

Renee LIN

Passionate about web dev and data analysis. Huge FFXIV fan. Interested in health data now.