WebGIS-Openlayers3+postgis+pgrouting最短路径

本文环境 postgresql+postgis+pgrouting
首先,了解一下Dijkstra算法,可参考链接http://www.cnblogs.com/biyeymyhjob/archive/2012/07/31/2615833.html
然后,阅读pgRouting手册,最好将其中例子操作一遍。重点看charpter 2/2.2 Sample Data;charpter3;charpter4;
最后展示本人做的demo。根据起点和终点名称查询路径。准备工作如下:

select * from highway
//添加起点id
//添加终点id
//添加道路权重值
ALTER TABLE highway ADD COLUMN source integer;  
ALTER TABLE highway ADD COLUMN target integer;  
ALTER TABLE highway ADD COLUMN length double precision;  
UPDATE highway SET length = ST_Length(geom);

//————————创建拓扑结构——————————————-
select pgr_createTopology(‘highway’,0.001,source:=’source’,id:=’gid’,target:=’target’,the_geom:=’geom’);

//————————查询起点节点是30,终点节点是60的最短路径——————————————–

SELECT * FROM pgr_dijkstra(‘SELECT gid as id, source::integer, target::integer,  length::double precision as cost  FROM highway’,  
                    30, 60, false, false); 

//—————-查询所经过的所有点——————–
SELECT * FROM pgr_dijkstra(–st_astext(geom)
‘SELECT gid as id, source::integer, target::integer, length::double precision as cost FROM highway’,30, 60, false, false) as di
join highway pt
on di.id2 = pt.gid;

//——————将路径写入一个几何文件dijkstra_res2内 —————-
SELECT seq, id1 AS node, id2 AS edge, cost, geom into dijkstra_res2 FROM pgr_dijkstra(
‘SELECT   gid as id,source::integer, target::integer, length::double precision as cost  FROM highway’, 30, 60, false, false) as di
join highway pt
on di.id2 = pt.gid;

准备工作做好后,就可以写数据库函数了,然后在geoserver中发布视图服务!

可参考http://blog.csdn.net/freeland1/article/details/49737793

http://blog.csdn.net/freeland1/article/details/42171949

http://www.cnblogs.com/nidaye/p/4567761.html

http://blog.csdn.net/longshengguoji/article/details/46051111

转载自:https://blog.csdn.net/u012121187/article/details/52979607

You may also like...