Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Calculate Average Street Circuity Using OSMnx stats Module
Next article icon

Calculate Graph Total Edge Length Using Python OSMnx Stats Module

Last Updated : 18 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will see how to calculate graphs' total edge length using the OSMNx stats Module. Explore urban connectivity with precision using the OSMnx stats module, which allows us to effortlessly calculate the total edge length of graphs derived from OpenStreetMap data, providing valuable insights into the intricate web of urban transportation networks.

Syntax of osmnx.stats.edge_length_total() Function

The OSMnx functionality to calculate graphs total edge length as follows:

osmnx.stats.edge_length_total(G)

Parameters: G (networks.MultiDiGraph) – input graph

Returns: Length – total length (meters) of edges in graph

Return Type: Float

Calculate Graph Total Edge Length Using Python OSMnx Stats Module

Below is the example by which we can understand how to calculate a graph's total edge length using the Python OSMnx Stats module:

Here we are using the OSMnx library to work with OpenStreetMap data. It imports the library as "ox" and loads the road network graph of Thiruvananthapuram, Kerala. It then calculates the total length of all edges in the graph and prints the result as "Edge Length." OSMnx simplifies the process of retrieving and analyzing urban spatial data.

Python3
import osmnx as ox  # load thiruvananthapuram city place = "Thiruvananthapuram, Kerala" G = ox.graph_from_place(place, network_type="drive")  # calulate edge length edge_length = ox.stats.edge_length_total(G) print("Edge Length:", edge_length) 

Output

Edge Length: 6821990.129999919

Below code is used to convert a MultiDiGraph (G) representing a road network obtained using OSMnx to GeoDataFrames (gdf_nodes and gdf_edges). below code then retrieves the 'length' column from the GeoDataFrame representing the edges (gdf_edges). This 'length' column likely contains the length information for each edge in the road network.

Python3
# convert multidigraph to geodataframe gdf_nodes, gdf_edges = ox.utils_graph.graph_to_gdfs(G) gdf_edges['length'] 

Output:

u            v            key
245581590 6344359035 0 30.210
6953034607 0 25.319
1668239990 0 59.960
247400396 5703878990 0 10.404
2451875170 0 21.593
...
11640476116 7497075885 0 60.176
11671347212 6979179664 0 91.440
11671703314 7496850667 0 139.222
11722175085 11224752412 0 22.735
11722175891 6979029912 0 39.723
Name: length, Length: 69832, dtype: float64

Next Article
Calculate Average Street Circuity Using OSMnx stats Module
author
sonugeorge
Improve
Article Tags :
  • Python
  • Python-Library
Practice Tags :
  • python

Similar Reads

  • Calculate Euclidean Distance Using Python OSMnx Distance Module
    Euclidean space is defined as the line segment length between two points. The distance can be calculated using the coordinate points and the Pythagoras theorem. In this article, we will see how to calculate Euclidean distances between Points Using the OSMnx distance module. Syntax of osmnx.distance.
    4 min read
  • Calculate Average Street Circuity Using OSMnx stats Module
    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,
    2 min read
  • Calculate Great Circle Distances Between Pairs of Points Using OSMnx Module
    The Great Circle Distance evaluates the shortest distance between two points considering Earth as a sphere. It is an arc linking two points on a sphere. Here, we will see how to calculate great circle distances between pairs of points using the OSMnx distance module. Syntax of osmnx.distance.great_c
    3 min read
  • Find the Nearest Edge to a Point Using Python OSMnx Distance Module
    OSMnx distance module can find the nearest edge to a point using the nearest_edges functionality. In this article, we will see how to find the nearest edge to a point using the OSMnx distance Module in Python. Syntax of osmnx.distance.nearest_edges() FunctionHere, the below function uses an R-tree s
    5 min read
  • Use Pandas to Calculate Statistics in Python
    Performing various complex statistical operations in python can be easily reduced to single line commands using pandas. We will discuss some of the most useful and common statistical operations in this post. We will be using the Titanic survival dataset to demonstrate such operations. [GFGTABS] Pyth
    7 min read
  • Calculate Compass Bearing Using Python OSMnx Bearing Module
    Bearing is a significant angle for Geographic Information System (GIS) applications. In this article, we will see how to calculate the compass Bearing using the OSMnx bearing module based on lat-Ion Points. What is Bearing?Bearing represents the clockwise angle in degrees between the north and the g
    3 min read
  • Calculate Undirected Graph's Orientation Entropy Using OSMnx Bearing Module
    The measure of entropy describes the heterogeneity of data. For street network modeling, the entropy reveals a city's street order and disorder. Cities with high orientation entropy show that the streets are spread out as much as possible. While low orientation entropy means that the streets are nea
    4 min read
  • Operations on Graph and Special Graphs using Networkx module | Python
    This article shows how to create an undirected Graph. This article continues for other types of Graphs and visualization techniques. The basic Graph operations are as follows: Getting Subgraph from a Graph : Given a Graph, if we are given a subset of its set of nodes, we can create a Subgraph by sel
    8 min read
  • Ladder Graph Using Networkx Module in Python
    In this article, we are going to see the ladder graph using Python. It is a graph that looks like ladders used commonly with every node attached to two other nodes in a specific manner. We can obtain a ladder graph by joining two-path graphs of n nodes each by each node connected with a correspondin
    2 min read
  • Complete Graph using Networkx in Python
    A complete graph also called a Full Graph it is a graph that has n vertices where the degree of each vertex is n-1. In other words, each vertex is connected with every other vertex. Example: Complete Graph with 6 edges: Properties of Complete Graph: The degree of each vertex is n-1.The total number
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences