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

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

Lesson guide

Tutorial details

Language
English
Level
Beginner

In this second part of the series, we focus on creating the node layer — a crucial component of any routing system.

Using the clean road line data (grid_lines) from Part 1, we extract key intersection points and line vertices, which will act as nodes in our network graph. These nodes are the building blocks for connecting paths and calculating routes.

✅ What’s Covered in this Video:

  • Create a network_nodes table
    A dedicated table is created to store all points (nodes) that represent intersections or line segment vertices.

  • Extract vertices from each LineString
    With ST_DumpPoints(), we extract every start/end and bend point of each line segment, converting them into point geometries.

  • Detect & insert intersection nodes
    Additional nodes are generated from actual road intersections using ST_Intersection() — critical for building a real-world network.

  • Deduplicate nodes
    Since many lines may share points, we clean the node list using DISTINCT ON (geom) to ensure each node appears only once.

  • Apply spatial index
    A GIST index is created on the network_nodes table for fast nearest-neighbor and routing operations.


💡 Why This Step Matters:

Every pathfinding algorithm — like Dijkstra — works on a graph made of nodes and edges. This step gives life to the "nodes" of our graph, accurately reflecting the geometry and connectivity of the real-world road network.

In the next part, we'll use these nodes to build edges (connections) between them and assign costs based on real-world distances.

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.