Open In App

Calculate Average Street Circuity Using OSMnx stats Module

Last Updated : 15 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Circuity is defined as a lack of straightforwardness and it is a result of a circulation network configuration. It impacts how we use urban space for settlement and travel. Calculating the average circuity of a city provides insights about direct routes in a transportation network. In this article, we will see how to calculate average street circuity using OSMnx stats Module

Syntax

It is the sum of edge lengths divided by the sum of straight-line distances between edge endpoints. If projected, it calculates straight-line distance as Euclidean distance. if unprojected, OSMnx uses great-circle distance. The OSMnx stats module for calculating average circuity is as follows:

osmnx.stats.circuity_avg(Gu)

Parameters : Gu (networkx.MultiGraph) – undirected input graph

Returns : circuity_avg – the graph’s average undirected edge circuity

Return Type : Float

Calculate Average Street Circuity Using OSMnx stats Module

Below, are the example explanation of how to calculate average street circuity using OSMns stats Module.

Exmple 1: Thiruvananthapuram Road Network Analysis

In this example, below code fetches Thiruvananthapuram’s road network data using OSMnx, converting it to an undirected graph and calculating the average circuity, reflecting actual vs. Euclidean distance traveled by vehicles.

Python3
import osmnx as ox

# fetch thiruvananthapuram drive data
tvm_multi_digraph = ox.graph_from_place(
  'Thiruvananthapuram, Kerala', network_type="drive")

# convert it into undirected graph
tvm_mdigraph_undirected = ox.utils_graph.get_undirected(tvm_multi_digraph)

# calculate average circuity
ox.stats.circuity_avg(tvm_mdigraph_undirected)

Output

1.0745635242029212


Example 2: Chongqing Road Network Analysis

In this example, below code uses OSMnx to retrieve Chongqing’s road network data for driving. It then converts the directed graph to an undirected one and computes the average circuity, measuring the deviation between actual road distance and Euclidean distance for the city’s road network.

Python3
import osmnx as ox

# fetch data
chn_mdigraph = ox.graph_from_place('Chongqing, China', 
                                   network_type="drive")
# convert to undirected graph
chn_mdigraph_undirected = ox.utils_graph.get_undirected(chn_mdigraph)

#calculate average circuity
ox.stats.circuity_avg(chn_mdigraph_undirected)

Output

1.2497905525217108


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads