pgRouting Manual (2.2)

pgr_drivingDistance (V2.0)

«  pgr_kDijkstra - Mutliple destination Shortest Path Dijkstra   ::   Contents   ::   pgr_dijkstra (V 2.0)- Shortest Path Dijkstra  »

pgr_drivingDistance (V2.0)

Name

pgr_drivingDistance - Returns the driving distance from a start node.

Synopsis

This function computes a Dijkstra shortest path solution them extracts the cost to get to each node in the network from the starting node. Using these nodes and costs it is possible to compute constant drive time polygons. Returns a set of pgr_costResult (seq, id1, id2, cost) rows, that make up a list of accessible points.

pgr_costResult[] pgr_drivingDistance(text sql, integer source, double precision distance,
                              boolean directed, boolean has_rcost);

Warning

This signature is being deprecated on version 2.1, Please use it without the has_rcost flag instead:

pgr_drivingDistance(sql, start_v, distance, directed)

See pgr_drivingDistance

Description

sql:

a SQL query, which should return a set of rows with the following columns:

SELECT id, source, target, cost [,reverse_cost] FROM edge_table
id:int4 identifier of the edge
source:int4 identifier of the source vertex
target:int4 identifier of the target vertex
cost:float8 value, of the edge traversal cost. A negative cost will prevent the edge from being inserted in the graph.
reverse_cost:(optional) the cost for the reverse traversal of the edge. This is only used when the directed and has_rcost parameters are true (see the above remark about negative costs).
source:

int4 id of the start point

distance:

float8 value in edge cost units (not in projection units - they might be different).

directed:

true if the graph is directed

has_rcost:

if true, the reverse_cost column of the SQL generated set of rows will be used for the cost of the traversal of the edge in the opposite direction.

Returns set of pgr_costResult[]:

seq:row sequence
id1:node ID
id2:edge ID (this is probably not a useful item)
cost:cost to get to this node ID

Warning

You must reconnect to the database after CREATE EXTENSION pgrouting. Otherwise the function will return Error computing path: std::bad_alloc.

History

  • Renamed in version 2.0.0

Examples

  • Without reverse_cost
  • With reverse_cost
SELECT * FROM pgr_drivingDistance(
    'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost FROM edge_table',
    7, 1.5, false, false
) ;
NOTICE:  Deprecated function
 seq | id1 | id2 | cost 
-----+-----+-----+------
   0 |   7 |  -1 |    0
   1 |   8 |   6 |    1
(2 rows)

SELECT * FROM pgr_drivingDistance(
    'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost FROM edge_table',
    7, 1.5, true, true
) ;
NOTICE:  Deprecated function
 seq | id1 | id2 | cost 
-----+-----+-----+------
   0 |   7 |  -1 |    0
   1 |   8 |   6 |    1
(2 rows)

The queries use the Sample Data network.

See Also

«  pgr_kDijkstra - Mutliple destination Shortest Path Dijkstra   ::   Contents   ::   pgr_dijkstra (V 2.0)- Shortest Path Dijkstra  »