🗺️ QGIS Network Analysis: Shortest Path Finder for Philippine Roads This project demonstrates how to perform network analysis using QGIS and Python. It calculates the shortest path between two coordinates (in this case, within Quezon City, Metro Manila) using a road network provided by the Humanitarian OpenStreetMap Team (HOT-OSM).
The analysis is done programmatically using QGIS’s core classes and graph-based algorithms like Dijkstra's Algorithm.
📌 Features Load vector road data from a GeoPackage (.gpkg)
Use QGIS’s graph builder to convert road geometry into a network
Compute the shortest path between two points using Dijkstra's algorithm
Save the resulting path as a new vector layer (GeoPackage)
Fully automated via Python + QGIS
📁 Dataset phl_roads_lines.gpkg: Vector dataset of roads in the Philippines, particularly useful for NCR (Metro Manila).
Source: Humanitarian OpenStreetMap Team
🧠 Requirements QGIS (>= 3.x) installed on your system
Python (3.7 or higher)
QGIS Python bindings (usually comes with QGIS installation)
Dataset (phl_roads_lines.gpkg) in the project directory
⚙️ Setup and Execution
- Install QGIS
sudo apt install qgis python3-qgis
- Ensure the qgis.core, qgis.analysis, and PyQt5 modules are available.
- Run the Script
python3 shortest_path.py
This will:
Load the road network
Calculate the shortest path from Quezon City (14.6760, 121.0365) to a destination point (14.5550, 121.0000)
Save the path in shortest_path.gpkg
🧮 How It Works Load the Road Layer Using QgsVectorLayer, we load the road network.
Define Points Define start_point and end_point using QgsPointXY.
Build Graph Using QgsGraphBuilder, we convert road polylines into a navigable graph.
Shortest Path Calculation Apply QgsGraphAnalyzer.dijkstra() to compute the least-cost route.
Export Path Write the result as a LineString into a new .gpkg file with proper attribute fields.
🧪 Output ✅ shortest_path.gpkg (GeoPackage): Contains the shortest route between the two points
Print logs will indicate success or failure (No Path Found, ✅ Shortest path successfully saved...)
🧵 Sample Use Cases Urban route optimization
Disaster response routing
Transportation research
Academic GIS projects
🤝 Acknowledgments QGIS Development Team
Humanitarian OpenStreetMap Team (HOT)
PyQGIS Developer Docs