pgr_withPointsCostMatrix - proposed - pgRouting Manual (3.2)
pgr_withPointsCostMatrix - proposed
pgr_withPointsCostMatrix
- 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.
-
They are not officially in the current release.
-
They will likely officially be part of the next mayor release:
-
The functions make use of ANY-INTEGER and ANY-NUMERICAL
-
Name might not change. (But still can)
-
Signature might not change. (But still can)
-
Functionality might not change. (But still can)
-
pgTap tests have being done. But might need more.
-
Documentation might need refinement.
-
Availability
-
Version 2.2.0
-
New proposed function
-
Description
-
TBD
Signatures
Summary
pgr_withPointsCostMatrix(edges_sql, points_sql, start_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 default
- The minimal signature:
-
-
Is for a directed graph.
-
The driving side is set as b both. So arriving/departing to/from the point(s) can be in any direction.
-
pgr_withPointsCostMatrix(edges_sql, points_sql, start_vid)
RETURNS SET OF (start_vid, end_vid, agg_cost)
- Example :
-
Cost matrix for points \(\{1, 6\}\) and vertices \(\{3, 6\}\) on a directed graph
SELECT * FROM pgr_withPointsCostMatrix(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction from pointsOfInterest',
array[-1, 3, 6, -6]);
start_vid end_vid agg_cost
-----------+---------+----------
-6 -1 1.3
-6 3 4.3
-6 6 1.3
-1 -6 1.3
-1 3 5.6
-1 6 2.6
3 -6 1.7
3 -1 1.6
3 6 1
6 -6 1.3
6 -1 2.6
6 3 3
(12 rows)
Complete Signature
pgr_withPointsCostMatrix(edges_sql, points_sql, start_vids,
directed:=true, driving_side:='b')
RETURNS SET OF (start_vid, end_vid, agg_cost)
- Example :
-
Cost matrix for points \(\{1, 6\}\) and vertices \(\{3, 6\}\) on an undirected graph
-
Returning a symmetrical cost matrix
-
Using the default side value on the points_sql query
-
Using the default driving_side value
SELECT * FROM pgr_withPointsCostMatrix(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction from pointsOfInterest',
array[-1, 3, 6, -6], directed := false);
start_vid end_vid agg_cost
-----------+---------+----------
-6 -1 1.3
-6 3 1.7
-6 6 1.3
-1 -6 1.3
-1 3 1.6
-1 6 2.6
3 -6 1.7
3 -1 1.6
3 6 1
6 -6 1.3
6 -1 2.6
6 3 1
(12 rows)
Parameters
Parameter |
Type |
Description |
---|---|---|
edges_sql |
|
Edges SQL query as described above. |
points_sql |
|
Points SQL query as described above. |
start_vids |
|
Array of identifiers of starting vertices. When negative: is a point’s pid. |
directed |
|
(optional). When
|
driving_side |
|
|
Returns SET OF
(start_vid,
end_vid,
agg_cost)
Column |
Type |
Description |
---|---|---|
start_vid |
|
Identifier of the starting vertex. |
end_vid |
|
Identifier of the ending vertex. |
agg_cost |
|
Aggregate cost from
|
Inner query
Column |
Type |
Default |
Description |
---|---|---|---|
id |
|
Identifier of the edge. |
|
source |
|
Identifier of the first end point vertex of the edge. |
|
target |
|
Identifier of the second end point vertex of the edge. |
|
cost |
|
Weight of the edge (source, target)
|
|
reverse_cost |
|
-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 |
|
(optional) Identifier of the point.
|
edge_id |
|
Identifier of the "closest" edge to the point. |
fraction |
|
Value in <0,1> that indicates the relative postition from the first end point of the edge. |
side |
|
(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
Additional Examples
- Example :
-
pgr_TSP using
pgr_withPointsCostMatrix
for points \(\{1, 6\}\) and vertices \(\{3, 6\}\) on an undirected graph
SELECT * FROM pgr_TSP(
$$
SELECT * FROM pgr_withPointsCostMatrix(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ORDER BY id',
'SELECT pid, edge_id, fraction from pointsOfInterest',
array[-1, 3, 6, -6], directed := false);
$$,
randomize := false
);
seq node cost agg_cost
-----+------+------+----------
1 -6 0 0
2 -1 1.3 1.3
3 3 1.6 2.9
4 6 1 3.9
5 -6 1.3 5.2
(5 rows)
See Also
-
sampledata network.
Indices and tables