Skip to main content
GIS-Schools GIS-Schools
Step-by-step tutorial

Shortest Path Routing with PostGIS - PGRouting - Network Analysis - Complete Web Project - Part 5

Lesson guide

Tutorial details

Language
English
Level
Beginner

In this final technical part of the routing series, we make our shortest path engine dynamic and ready for real-time use — by using input points and materialized views.

This structure allows the system to automatically calculate and refresh the shortest route whenever the user provides a new start and end point — perfect for web apps, QGIS visualizations, or mobile GIS solutions.


✅ What’s Covered in this Video:

  • Create a points table
    A simple table to store user-defined start and end points for routing.

  • Dynamic shortest path using Materialized View
    We create mv_short_path — a view that:

    • Finds the nearest network node to the start point

    • Finds the nearest network node to the end point

    • Runs pgr_dijkstra() between these two nodes

    • Returns the full geometry of the resulting route

  • Refresh logic for re-routing
    By simply updating the points table and calling REFRESH MATERIALIZED VIEW, the route updates automatically — no manual query rewriting needed!


💡 Why This Step is Powerful:

This approach turns your routing engine into an interactive, user-driven service — ideal for frontend integration. Whether you're building:

  • a QGIS plugin

  • a Leaflet-based web portal

  • or an API for mobile navigation

This dynamic logic allows users to select any two locations and instantly receive the shortest path.

Lesson downloads

Tutorial resources

Download the files attached to this published lesson.

Muhammad Sohail
Written by

Muhammad Sohail

Web Developer

I am a highly skilled GIS Specialist with a proven track record of delivering high-quality GIS solutions to clients. My expertise in GIS software development, geodatabase design and management, data analysis and visualization, remote sensing, GIS training and support, and GIS consulting. With my technical skills, critical thinking, and business acumen, I am confident in my ability to provide excellent GIS services to clients and deliver results that exceed their expectations.

Discussion

Comments

0

No comments yet. Start the discussion.

Join the discussion

Leave a reply

Your email address will not be published. Required fields are marked.