Skip to main content
The pgRouting extension extends PostgreSQL and PostGIS to provide geospatial routing and network analysis functionality. It enables you to perform shortest path calculations, traveling salesperson solutions, and other routing operations on spatial networks like road networks. Your Nile database arrives with the pgRouting extension and its dependency postgis already enabled.

Understanding pgRouting

pgRouting works with network topologies stored in PostgreSQL/PostGIS. A network topology consists of:
  • Vertices (nodes/intersections)
  • Edges (segments/roads)
  • Costs (distance, time, or other metrics)

Key Features

  • Multiple Routing Algorithms: Dijkstra, A*, Traveling Salesperson Problem (TSP)
  • Flexible Cost Calculations: Support for distance, time, and custom cost functions
  • Turn Restriction Support: Handle real-world routing constraints
  • Dynamic Cost Updates: Modify costs based on traffic or other conditions
  • Large Network Support: Efficient handling of large road networks

Usage Examples

Let’s create a simple road network and perform various routing operations.

Creating the Network Table

Inserting Sample Data

Basic Shortest Path Query

Using Dijkstra’s algorithm:
When you have geographic coordinates:

Driving Distance

Find all reachable nodes within a certain cost:

Common Use Cases

  • Navigation systems
  • Delivery route optimization
  • Service area analysis
  • Emergency response planning
  • Public transport routing
  • Traffic impact analysis

Limitations

  • Memory usage increases with network size
  • Some algorithms have exponential complexity
  • Real-time updates can be challenging
  • Turn restrictions increase complexity
  • Limited support for time-dependent routing

Additional Resources