Unsupported versions:2.6 2.5 2.4 2.3 2.2
pgr_withPointsCost
¶
pgr_withPointsCost
- 计算最短路径,并只返回所给点组合的最短路径的总成本。
可用性
Version 4.0.0
函数正式发布。
Driving side parameter is unnamed and compulsory.
Valid values depend on kind of graph
Output columns standardized to
(start_vid, end_vid, agg_cost)
Breaking change, signatures no longer available:
pgr_withpointscost(text,text,anyarray,anyarray,boolean,character)
pgr_withpointscost(text,text,anyarray,bigint,boolean,character)
pgr_withpointscost(text,text,bigint,anyarray,boolean,character)
pgr_withpointscost(text,text,bigint,bigint,boolean,character)
pgr_withpointscost(text,text,text,boolean,character)
版本3.2.0
新提议的签名:
pgr_withPointsCost(组合)
版本 2.2.0
新提议的函数。
描述¶
修改图形以包含由 points_sql 定义的点。使用 Dijkstra 算法,只返回找到的最短路径的总成本。
主要特点是:
仅在具有正成本的边进行处理。
它不返回路径。
返回修改图中顶点对组合的最短路径成本之和。
The returned values are in the form of a set of
(start_vid, end_vid, agg_cost)
.
图的顶点是:
当它属于edges_sql时为 正
当它属于 points_sql时为 负
当存在路径时返回值。
当起始顶点和结束顶点相同时,就没有路径。
非包含值 (v, v) 中的 agg_cost 为 0
当起始顶点和结束顶点不同且不存在路径时:
非包含值 (u, v) 中的 agg_cost 为
如果返回的值存储在表中,则唯一索引将是这一对: (start_vid, end_vid) 。
对于 无向 图,结果是 对称 的。
(u, v) 的 agg_cost 与 (v, u) 相同。
For optimization purposes, any duplicated value in the input arrays of start vids or end vids or are ignored.
返回值是有序的:
start_vid 升序
end_vid 升序
运行时间:
签名¶
总结
[directed]
(start_vid, end_vid, agg_cost)
的集合Note
与 withPoints 函数系列的其他成员不同,没有 详细信息 标志。
One to One¶
[directed]
(start_vid, end_vid, agg_cost)
的集合From point
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, 10,'r');
start_vid | end_vid | agg_cost
-----------+---------+----------
-1 | 10 | 6.4
(1 row)
一对多¶
[directed]
(start_vid, end_vid, agg_cost)
的集合无向图上的点
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, ARRAY[-3, 7], 'B',
directed => false);
start_vid | end_vid | agg_cost
-----------+---------+----------
-1 | -3 | 3.2
-1 | 7 | 1.6
(2 rows)
Many to One¶
[directed]
(start_vid, end_vid, agg_cost)
的集合- 示例:
From point
and vertex to point with right driving side in directed graph.
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1, 6], -3, 'R');
start_vid | end_vid | agg_cost
-----------+---------+----------
-1 | -3 | 4
6 | -3 | 2.6
(2 rows)
Many to Many¶
[directed]
(start_vid, end_vid, agg_cost)
的集合- 示例:
From point
and vertex to point and vertex with left side driving.
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1, 6], ARRAY[-3, 1], 'L');
start_vid | end_vid | agg_cost
-----------+---------+----------
-1 | -3 | 3.2
-1 | 1 | 3.6
6 | -3 | 2.6
6 | 1 | 3
(4 rows)
组合¶
[directed]
(start_vid, end_vid, agg_cost)
的集合- 示例:
两种组合
From point
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
'SELECT * FROM (VALUES (-1, 10), (6, -3)) AS combinations(source, target)',
'r');
start_vid | end_vid | agg_cost
-----------+---------+----------
-1 | 10 | 6.4
6 | -3 | 2.6
(2 rows)
参数¶
列 |
类型 |
描述 |
---|---|---|
|
Edges SQL 如下所述 |
|
|
Points SQL 如下所述 |
|
|
Combinations SQL 如下所述 |
|
start vid |
|
路径起始顶点的标识符。 负值用于点的标识符。 |
start vids |
|
起始顶点的标识符数组。 负值用于点的标识符。 |
end vid |
|
路径结束顶点的标识符。 负值用于点的标识符。 |
end vids |
|
结束顶点的标识符数组。 负值用于点的标识符。 |
driving side |
|
值在 [
|
可选参数¶
列 |
类型 |
默认 |
描述 |
---|---|---|---|
|
|
|
|
内部查询¶
Edges SQL¶
列 |
类型 |
默认 |
描述 |
---|---|---|---|
|
ANY-INTEGER |
边的标识符。 |
|
|
ANY-INTEGER |
边的第一个端点顶点的标识符。 |
|
|
ANY-INTEGER |
边的第二个端点顶点的标识符。 |
|
|
ANY-NUMERICAL |
edge ( |
|
|
ANY-NUMERICAL |
-1 |
边(
|
其中:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
- ANY-NUMERICAL:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Points SQL¶
参数 |
类型 |
默认 |
描述 |
---|---|---|---|
|
ANY-INTEGER |
value |
点的标识符。
|
|
ANY-INTEGER |
距离该点“最近”的边的标识符。 |
|
|
ANY-NUMERICAL |
<0,1> 中的值指示距边缘第一个端点的相对位置。 |
|
|
|
|
[
|
其中:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
- ANY-NUMERICAL:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
分量 SQL¶
参数 |
类型 |
描述 |
---|---|---|
|
ANY-INTEGER |
出发顶点的标识符。 |
|
ANY-INTEGER |
到达顶点的标识符。 |
其中:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
结果列¶
(start_vid, end_vid, agg_cost)
的集合
列 |
类型 |
描述 |
---|---|---|
|
|
起始顶点的标识符。 |
|
|
结束顶点的标识符。 |
|
|
从 |
Note
当 start_vid 或 end_vid 列具有负值时,标识符用于点。
其他示例¶
在 Points SQL 中使用 pgr_findCloseEdges 。¶
求从顶点
SELECT * FROM pgr_withPointsCost(
$e$ SELECT * FROM edges $e$,
$p$ SELECT edge_id, round(fraction::numeric, 2) AS fraction, side
FROM pgr_findCloseEdges(
$$SELECT id, geom FROM edges$$,
(SELECT ST_POINT(2.9, 1.8)),
0.5, cap => 2)
$p$,
1, ARRAY[-1, -2],'B', false);
start_vid | end_vid | agg_cost
-----------+---------+----------
1 | -2 | 2.9
1 | -1 | 3.2
(2 rows)
点
最近的边。点
的下一个闭合边。靠近图表并不意味着路线更短。
右侧驾驶拓扑¶
从点
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[5, -1], ARRAY[-2, -3, -6, 10, 11],
'r');
start_vid | end_vid | agg_cost
-----------+---------+----------
-1 | -6 | 2.1
-1 | -3 | 4
-1 | -2 | 4.8
-1 | 10 | 6.4
-1 | 11 | 3.4
5 | -6 | 1.7
5 | -3 | 3.6
5 | -2 | 4.4
5 | 10 | 6
5 | 11 | 3
(10 rows)
左侧驾驶拓扑¶
从点
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[5, -1], ARRAY[-2, -3, -6, 10, 11],
'l');
start_vid | end_vid | agg_cost
-----------+---------+----------
-1 | -6 | 1.3
-1 | -3 | 3.2
-1 | -2 | 5.2
-1 | 10 | 5.6
-1 | 11 | 2.6
5 | -6 | 1.7
5 | -3 | 3.6
5 | -2 | 5.6
5 | 10 | 6
5 | 11 | 3
(10 rows)
与驱动端驱动拓扑无关¶
从点
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[5, -1], ARRAY[-2, -3, -6, 10, 11], 'R');
start_vid | end_vid | agg_cost
-----------+---------+----------
-1 | -6 | 2.1
-1 | -3 | 4
-1 | -2 | 4.8
-1 | 10 | 6.4
-1 | 11 | 3.4
5 | -6 | 1.7
5 | -3 | 3.6
5 | -2 | 4.4
5 | 10 | 6
5 | 11 | 3
(10 rows)
另请参阅¶
索引和表格