码迷,mamicode.com
首页 > 其他好文 > 详细

pgrouting进行路径规划之入门二

时间:2015-05-09 16:32:22      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:dijkstra   pgrouting   opengis   最短路径   导航   

本文是在上一篇文章的基础上的。数据入库和字段设置请参考上篇文章。本文介绍利用pgrouting中其他方法来求取最短路径。

一、添加属性字段

为表格beijingmodified添加x1,y1,x2,y2字段

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);

技术分享

pgrouting进行路径规划之入门二

标签:dijkstra   pgrouting   opengis   最短路径   导航   

原文地址:http://blog.csdn.net/longshengguoji/article/details/45602219

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!