标签:.com pgrouting 查询 targe 经历 几何 应该 工作 bsp
1、ALTER TABLE beijing_line ADD COLUMN source integer;
ALTER TABLE beijing_line ADD COLUMN target integer;
ALTER TABLE beijing_line ADD COLUMN length double precision;
UPDATE beijing_line SET length = ST_Length(the_geom);
ps:执行createTopology这个函数之前一定得对数据库执行以下三句sql查询:
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION fuzzystrmatch;
2、select pgr_createTopology(‘beijing_line‘,0.001,source:=‘source‘,id:=‘gid‘,target:=‘target‘,the_geom:=‘the_geom‘);
select pgr_createTopology(‘beijing_line‘,0.1,source:=‘source‘,id:=‘gid‘,target:=‘target‘,the_geom:=‘the_geom’);
把容差值设置的大一点,可能结果会好点
3、 SELECT * FROM pgr_dijkstra(‘
SELECT gid as id,
source::integer,
target::integer,
length::double precision as cost
FROM beijing_line‘,
30, 60, false, false);
无查询结果就执行下面这几个试一试,也可能是两点之间就没有路径
select source from beijing_line;
select target from beijing_line;
select length from beijing_line;
4、查询所经过的所有点:
SELECT st_astext(the_geom) FROM pgr_dijkstra(‘
SELECT gid AS id,
source::integer,
target::integer,
length::double precision AS cost
FROM beijing_line‘,
30, 60, false, false) as di
join beijing_line pt
on di.id2 = pt.gid;
5、将路径写入一个几何文件内:
SELECT seq, id1 AS node, id2 AS edge, cost,the_geom into dijkstra_res FROM pgr_dijkstra(‘
SELECT gid AS id,
source::integer,
target::integer,
length::double precision AS cost
FROM beij hbs90.cn ing_line‘,
30, 60, false, false) as di
join beijing_line pt
on di.id2 = pt. senta77.com gid;
经历过以上的步骤,如果一切顺利,应该能看到结果,这里不再截图。这时初步的准备工作已经完成。
参考博文如下():
postgresql+postgis+pgrouting实现最短路径查询(1)---线数据的处理和建立拓扑
标签:.com pgrouting 查询 targe 经历 几何 应该 工作 bsp
原文地址:https://www.cnblogs.com/eryaketang/p/8968277.html