postgresql+postgis+pgrouting實現最短路徑查詢(1)---線資料的處理和建立拓撲

來源:互聯網
上載者:User

標籤:.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)---線資料的處理和建立拓撲

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.