Convert Figma logo to code with AI

pgRouting logopgrouting

Repository contains pgRouting library. Development branch is "develop", stable branch is "master"

1,285
376
1,285
58

Top Related Projects

9,805

A modular geospatial engine written in JavaScript and TypeScript

Open source routing engine for OpenStreetMap. Use it as Java library or standalone web server.

Open Source Routing Machine - C++ backend

Open Source Routing Engine for OpenStreetMap

11,615

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)

Quick Overview

pgRouting is an extension for PostgreSQL that adds routing and network analysis functionality to PostGIS/PostgreSQL databases. It provides a variety of routing algorithms for solving shortest path problems and other network-related queries, making it a powerful tool for spatial data analysis and GIS applications.

Pros

  • Seamless integration with PostgreSQL and PostGIS
  • Supports multiple routing algorithms (Dijkstra, A*, Traveling Salesman Problem, etc.)
  • Highly scalable for large datasets
  • Active community and regular updates

Cons

  • Steep learning curve for users new to PostgreSQL/PostGIS
  • Limited documentation for advanced use cases
  • Performance can be slower compared to specialized routing engines
  • Requires careful index management for optimal performance

Code Examples

  1. Finding the shortest path using Dijkstra's algorithm:
SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost FROM edges',
    1, 5
);
  1. Calculating a driving distance area:
SELECT * FROM pgr_drivingDistance(
    'SELECT id, source, target, cost FROM edges',
    1, 1000
);
  1. Solving the Traveling Salesman Problem:
SELECT * FROM pgr_TSP(
    $$SELECT * FROM pgr_dijkstraCostMatrix(
        'SELECT id, source, target, cost FROM edges',
        (SELECT array_agg(id) FROM vertices WHERE id IN (1, 2, 3, 4, 5))
    )$$
);

Getting Started

  1. Install PostgreSQL and PostGIS
  2. Install pgRouting extension:
CREATE EXTENSION pgrouting;
  1. Create a table for your network:
CREATE TABLE edges (
    id SERIAL PRIMARY KEY,
    source INTEGER,
    target INTEGER,
    cost FLOAT
);
  1. Import your network data into the table
  2. Run a simple query to test:
SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost FROM edges',
    1, 5
);

Competitor Comparisons

9,805

A modular geospatial engine written in JavaScript and TypeScript

Pros of Turf

  • JavaScript-based, making it easily integrable with web applications
  • Lightweight and can run entirely on the client-side
  • Extensive collection of geospatial analysis functions

Cons of Turf

  • Less suitable for large-scale, server-side processing
  • May have performance limitations with very large datasets
  • Lacks advanced routing capabilities found in pgRouting

Code Comparison

pgRouting (SQL):

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost FROM edges',
    1, 5
);

Turf (JavaScript):

const path = turf.shortestPath(point1, point2, {
  obstacles: polygons
});

While pgRouting excels in complex routing scenarios within PostgreSQL databases, Turf provides a more accessible approach for basic geospatial operations in JavaScript environments. pgRouting is better suited for large-scale, server-side routing tasks, whereas Turf shines in client-side applications and simpler geospatial analyses. The choice between them depends on the specific requirements of the project, such as data size, complexity of operations, and deployment environment.

Open source routing engine for OpenStreetMap. Use it as Java library or standalone web server.

Pros of GraphHopper

  • Standalone Java application, easier to deploy and integrate with other Java-based systems
  • Supports multiple routing algorithms (Dijkstra, A*, Contraction Hierarchies)
  • Built-in support for real-time traffic updates and time-dependent routing

Cons of GraphHopper

  • Requires loading entire graph into memory, which can be resource-intensive for large datasets
  • Less tightly integrated with PostgreSQL, may require additional setup for database interactions

Code Comparison

GraphHopper:

GraphHopper hopper = new GraphHopper().forServer();
hopper.setDataReaderFile("map-data.osm.pbf");
hopper.setGraphHopperLocation("routing-graph-cache");
hopper.setEncodingManager(EncodingManager.create("car"));
hopper.importOrLoad();

pgRouting:

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost FROM edges',
    1, 10, directed := true
);

Key Differences

  • GraphHopper is a standalone Java application, while pgRouting is a PostgreSQL extension
  • pgRouting leverages PostgreSQL's spatial capabilities, making it more suitable for GIS-heavy applications
  • GraphHopper offers more built-in routing algorithms and real-time traffic support out of the box

Open Source Routing Machine - C++ backend

Pros of osrm-backend

  • Faster performance for large-scale routing problems
  • Better suited for real-time applications and high-volume queries
  • Supports advanced features like traffic updates and time-dependent routing

Cons of osrm-backend

  • Steeper learning curve and more complex setup process
  • Less flexibility for custom routing algorithms and constraints
  • Requires more system resources and memory

Code Comparison

osrm-backend (C++):

#include <osrm/osrm.hpp>
#include <osrm/route_parameters.hpp>

osrm::OSRM osrm{"path/to/data.osrm"};
osrm::RouteParameters params;
params.coordinates.push_back({longitude1, latitude1});
params.coordinates.push_back({longitude2, latitude2});

pgrouting (SQL):

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost FROM edges',
    start_vid,
    end_vid
);

osrm-backend is optimized for high-performance routing on large road networks, making it ideal for applications requiring real-time responses. It offers advanced features like traffic updates but has a steeper learning curve.

pgrouting integrates seamlessly with PostgreSQL, providing flexibility for custom routing algorithms and easier integration with existing database systems. It's more suitable for smaller-scale routing problems and custom routing scenarios.

The code comparison shows that osrm-backend uses C++ for routing calculations, while pgrouting leverages SQL queries within PostgreSQL, reflecting their different approaches to routing problems.

Open Source Routing Engine for OpenStreetMap

Pros of Valhalla

  • Designed for large-scale, global routing with support for multimodal transportation
  • Offers real-time updates and dynamic costing
  • Provides advanced features like isochrones and map matching

Cons of Valhalla

  • Steeper learning curve and more complex setup compared to pgRouting
  • Requires more system resources for optimal performance
  • Less integrated with PostgreSQL ecosystem

Code Comparison

Valhalla (C++)

auto costing = sif::CreatePedestrianCost(options);
auto mode = sif::TravelMode::kPedestrian;
auto reader = new baldr::GraphReader(tile_dir);
auto path = PathAlgorithm::GetBestPath(origin, destination, reader, costing, mode);

pgRouting (SQL)

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost FROM edges',
    start_vid, end_vid
);

Both projects offer powerful routing capabilities, but Valhalla is more suited for large-scale, multimodal routing scenarios, while pgRouting excels in PostgreSQL-integrated environments with simpler setup and usage.

11,615

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)

Pros of QGIS

  • Comprehensive GIS functionality with a user-friendly GUI
  • Extensive plugin ecosystem for additional features
  • Supports a wide range of data formats and sources

Cons of QGIS

  • Larger resource footprint and slower performance for some operations
  • Steeper learning curve for non-GIS professionals
  • Less specialized for routing tasks compared to pgRouting

Code Comparison

QGIS (Python):

layer = QgsVectorLayer("path/to/shapefile.shp", "layer_name", "ogr")
if not layer.isValid():
    print("Layer failed to load!")
else:
    QgsProject.instance().addMapLayer(layer)

pgRouting (SQL):

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost FROM edge_table',
    10, 50, directed := false
);

QGIS is a full-featured desktop GIS application with a graphical interface, while pgRouting is a PostgreSQL extension for routing algorithms. QGIS offers a more comprehensive set of GIS tools and visualization capabilities, whereas pgRouting specializes in efficient routing calculations within a database environment. QGIS is better suited for general GIS tasks and map creation, while pgRouting excels in network analysis and routing operations integrated with spatial databases.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

pgRouting - Routing on PostgreSQL

Join the chat at
https://gitter.im/pgRouting/pgrouting Join discourse DOI

Branches

  • The main branch has the development of the next micro release
  • The develop branch has the development of the next minor/major release

For the complete list of releases go to: https://github.com/pgRouting/pgrouting/releases

For the release notes go to: https://docs.pgrouting.org/latest/en/release_notes.html

LINKS

STATUS

Status of the project can be found here

INTRODUCTION

pgRouting extends the PostGIS/PostgreSQL geospatial database to provide geospatial routing and other network analysis functionality.

This library contains the following features:

  • All Pairs Shortest Path Algorithms
  • A-star algorithm
  • Bi-directional algorithms
  • A variety of applications of Dijkstra algorithms
    • Cost functions
    • With points
  • Driving Distance
    • With points
  • Yen's algorithm
  • Traveling Sales Person (TSP)

and many more.

The latest documentation: https://docs.pgrouting.org/latest

REQUIREMENTS

Building requirements

  • perl
  • C and C++ compilers
    • Compiling with Boost 1.56 up to Boost 1.74 requires C++ Compiler with C++03 or C++11 standard support
    • Compiling with Boost 1.75 requires C++ Compiler with C++14 standard support
  • Postgresql = Supported version by PostgreSQL
    • Not supporting v12 & under
  • The Boost Graph Library (BGL) >= 1.56
  • CMake >= 3.12
  • 7.0 > Sphinx >= 4.0.0

User's requirements

  • PostGIS

COMPILATION

For MinGW on Windows

mkdir build
cd build
cmake -G"MSYS Makefiles" ..
make
make install

Also pre-built Windows binaries can be downloaded from https://postgis.net/windows_downloads

For Linux

mkdir build
cd build
cmake  ..
make
sudo make install

Build with documentation (requires Sphinx)

cmake -DWITH_DOC=ON ..

Postgresql

createdb mydatabase
psql mydatabase -c "CREATE EXTENSION pgrouting CASCADE"

USAGE

See online documentation: http://docs.pgrouting.org/latest/en/index.html

CITATION

To cite pgRouting in publications use:

BibTeX entry:

@Manual{,
  title = {{pgRouting: Routing on PostgreSQL}},
  author = {{pgRouting contributors}},
  year = {2025},
  doi = {10.5281/zenodo.15004469},
  url = {https://pgrouting.org/},
}

LICENSE

  • Most features are available under GPL-2.0-or-later
  • Some Boost extensions are available under Boost license (see LICENSE_1_0.txt)
  • Some code contributed by iMaptools.com is available under MIT-X license.