pgr_withPointsCost
- Calculates the shortest path and returns only the aggregate cost of the shortest path(s) found, for the combination of points given.
Warning
Proposed functions for next mayor release.
Availability
Support
Modify the graph to include points defined by points_sql. Using Dijkstra algorithm, return only the aggregate cost of the shortest path(s) found.
Summary
pgr_withPointsCost(edges_sql, points_sql, from_vid, to_vid [, directed] [, driving_side])
pgr_withPointsCost(edges_sql, points_sql, from_vid, to_vids [, directed] [, driving_side])
pgr_withPointsCost(edges_sql, points_sql, from_vids, to_vid [, directed] [, driving_side])
pgr_withPointsCost(edges_sql, points_sql, from_vids, to_vids [, directed] [, driving_side])
RETURNS SET OF (start_vid, end_vid, agg_cost)
Note
There is no details flag, unlike the other members of the withPoints family of functions.
Using defaults
pgr_withPointsCost(edges_sql, points_sql, start_vid, end_vid)
RETURNS SET OF (start_vid, end_vid, agg_cost)
Example: | From point \(1\) to point \(3\) |
---|
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, -3);
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -3 | 3.2
(1 row)
pgr_withPointsCost(edges_sql, points_sql, from_vid, to_vid [, directed] [, driving_side])
RETURNS SET OF (seq, node, edge, cost, agg_cost)
Example: | From point \(1\) to vertex \(3\) on an undirected graph. |
---|
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, 3,
directed := false);
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | 3 | 1.6
(1 row)
pgr_withPointsCost(edges_sql, points_sql, from_vid, to_vids [, directed] [, driving_side])
RETURNS SET OF (start_vid, end_vid, agg_cost)
Example: | From point \(1\) to point \(3\) and vertex \(5\) on a directed graph. |
---|
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, ARRAY[-3,5]);
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -3 | 3.2
-1 | 5 | 1.6
(2 rows)
pgr_withPointsCost(edges_sql, points_sql, from_vids, to_vid [, directed] [, driving_side])
RETURNS SET OF (start_vid, end_vid, agg_cost)
Example: | From point \(1\) and vertex \(2\) to point \(3\) on a directed graph. |
---|
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1,2], -3);
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -3 | 3.2
2 | -3 | 2.6
(2 rows)
pgr_withPointsCost(edges_sql, points_sql, from_vids, to_vids [, directed] [, driving_side])
RETURNS SET OF (start_vid, end_vid, agg_cost)
Example: | From point \(1\) and vertex \(2\) to point \(3\) and vertex \(7\) on a directed graph. |
---|
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1,2], ARRAY[-3,7]);
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -3 | 3.2
-1 | 7 | 3.6
2 | -3 | 2.6
2 | 7 | 3
(4 rows)
Parameter | Type | Description |
---|---|---|
edges_sql | TEXT |
Edges SQL query as described above. |
points_sql | TEXT |
Points SQL query as described above. |
start_vid | ANY-INTEGER |
Starting vertex identifier. When negative: is a point’s pid. |
end_vid | ANY-INTEGER |
Ending vertex identifier. When negative: is a point’s pid. |
start_vids | ARRAY[ANY-INTEGER] |
Array of identifiers of starting vertices. When negative: is a point’s pid. |
end_vids | ARRAY[ANY-INTEGER] |
Array of identifiers of ending vertices. When negative: is a point’s pid. |
directed | BOOLEAN |
(optional). When false the graph is considered as Undirected. Default is true which considers the graph as Directed. |
driving_side | CHAR |
|
Column | Type | Default | Description |
---|---|---|---|
id | ANY-INTEGER |
Identifier of the edge. | |
source | ANY-INTEGER |
Identifier of the first end point vertex of the edge. | |
target | ANY-INTEGER |
Identifier of the second end point vertex of the edge. | |
cost | ANY-NUMERICAL |
Weight of the edge (source, target)
|
|
reverse_cost | ANY-NUMERICAL |
-1 | Weight of the edge (target, source),
|
Where:
ANY-INTEGER: | SMALLINT, INTEGER, BIGINT |
---|---|
ANY-NUMERICAL: | SMALLINT, INTEGER, BIGINT, REAL, FLOAT |
Description of the Points SQL query
points_sql: | an SQL query, which should return a set of rows with the following columns: |
---|
Column | Type | Description |
---|---|---|
pid | ANY-INTEGER |
(optional) Identifier of the point.
|
edge_id | ANY-INTEGER |
Identifier of the “closest” edge to the point. |
fraction | ANY-NUMERICAL |
Value in <0,1> that indicates the relative postition from the first end point of the edge. |
side | CHAR |
(optional) Value in [‘b’, ‘r’, ‘l’, NULL] indicating if the point is:
|
Where:
ANY-INTEGER: | smallint, int, bigint |
---|---|
ANY-NUMERICAL: | smallint, int, bigint, real, float |
Column | Type | Description |
---|---|---|
start_vid | BIGINT |
Identifier of the starting vertex. When negative: is a point’s pid. |
end_vid | BIGINT |
Identifier of the ending point. When negative: is a point’s pid. |
agg_cost | FLOAT |
Aggregate cost from start_vid to end_vid . |
Example: | From point \(1\) and vertex \(2\) to point \(3\) and vertex \(7\), with right side driving topology |
---|
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1,2], ARRAY[-3,7],
driving_side := 'l');
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -3 | 3.2
-1 | 7 | 3.6
2 | -3 | 2.6
2 | 7 | 3
(4 rows)
Example: | From point \(1\) and vertex \(2\) to point \(3\) and vertex \(7\), with left side driving topology |
---|
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1,2], ARRAY[-3,7],
driving_side := 'r');
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -3 | 4
-1 | 7 | 4.4
2 | -3 | 2.6
2 | 7 | 3
(4 rows)
Example: | From point \(1\) and vertex \(2\) to point \(3\) and vertex \(7\), does not matter driving side. |
---|
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1,2], ARRAY[-3,7],
driving_side := 'b');
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -3 | 3.2
-1 | 7 | 3.6
2 | -3 | 2.6
2 | 7 | 3
(4 rows)
The queries use the Sample Data network.