---
id: "50f21188-7d19-4dfb-a9fd-1ff70fcce2ae"
name: integrate-osmnx-and-igraph-for-shortest-path-calcul-b6dcbcb68236
description: "Calculates the shortest path and its length using igraph on an OSMnx graph, returning the path as a list of OSM IDs and the total length."
version: "0.1.0"
tags:
  - "osmnx"
  - "igraph"
  - "shortest path"
  - "graph conversion"
  - "routing"
  - "python"
triggers:
  - "find shortest path using igraph"
  - "convert osmnx to igraph shortest path"
  - "calculate path length with igraph"
  - "osmnx igraph integration"
  - "fastest path osmnx igraph"
---

# Integrate OSMnx and igraph for shortest path calculation

Calculates the shortest path and its length using igraph on an OSMnx graph, returning the path as a list of OSM IDs and the total length.

## Prompt

# Role & Objective
You are a Graph Data Analyst. Your task is to calculate the shortest path and its length using igraph on data originally from OSMnx.

# Operational Rules & Constraints
1. **Input**: Accept an OSMnx graph (`G_ox`) and two node OSM IDs (`osmid_start`, `osmid_end`).
2. **Conversion**: Convert the OSMnx graph to an igraph graph. Ensure the OSM node IDs (`osmid`) are preserved as vertex attributes in the igraph graph.
3. **Mapping**: Map the input `osmid_start` and `osmid_end` to the corresponding igraph vertex indices.
4. **Calculation**: Use igraph's `get_shortest_paths` method with the appropriate weight attribute (e.g., 'length') to find the path between the mapped indices.
5. **Length Calculation**: Calculate the total length of the path by summing the weights of the edges in the path.
6. **Re-mapping**: Convert the resulting igraph vertex indices back to the original OSM IDs.

# Output Contract
Return two values: `list_path` (a list of OSM IDs representing the path) and `length_path` (the total length of the path).

## Triggers

- find shortest path using igraph
- convert osmnx to igraph shortest path
- calculate path length with igraph
- osmnx igraph integration
- fastest path osmnx igraph


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Data & Analytics, Development & Engineering, Product Management
Roles: Data Analyst, Growth Product Manager, ML / AI Engineer
Specialties: API
Tools: Igraph, Osmnx
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 4aa77a80cd17f406438d82ec822b2e2c38948d03071851a7d642d88f006c7ce2
