pgrouting进行路径规划之入门二

0
0
0
1. 云栖社区>
2. 博客>
3. 正文

# 一、添加属性字段

ALTER TABLE beijingmodified ADD COLUMN x1double precision;

ALTER TABLE beijingmodified ADD COLUMN y1double precision;

ALTER TABLE beijingmodified ADD COLUMN x2double precision;

ALTER TABLE beijingmodified ADD COLUMN y2double precision;

# 二、为新添加的属性字段赋值

UPDATE beijingmodified SET x1 =ST_x(ST_PointN(geom, 1));

UPDATE beijingmodified SET y1 =ST_y(ST_PointN(geom, 1));

UPDATE beijingmodified SET x2 =ST_x(ST_PointN(geom, ST_NumPoints(geom)));

UPDATE beijingmodified SET y2 =ST_y(ST_PointN(geom, ST_NumPoints(geom)));

# 三、查询

1.A*算法路径查询

SELECT seq, id1 AS node, id2 AS edge, costFROM pgr_astar('

SELECT gid AS id,

source::integer,

target::integer,

length::double precision AS cost,

x1, y1, x2, y2

FROM beijingmodified',30, 60, false,false);

2.pgr_kdijkstracost函数查询从出发点到目的地的消耗

SELECT seq, id1 AS source, id2 AS target,cost FROM pgr_kdijkstraCost('

SELECT gid AS id,

source::integer,

target::integer,

length::double precision AS cost

FROM beijingmodified',

30, array[60,70,100], false, false);

3. pgr_kdijkstraPath函数查询具体路径

SELECT seq, id1 AS path, id2 AS edge, costFROM pgr_kdijkstraPath('

SELECT gid AS id,

source::integer,

target::integer,

length::double precision AS cost

FROM beijingmodified',

30, array[60,100], false, false);

+ 关注

corcosa 15196人浏览