pgRouting
安装与配置可以参见两篇帖子:
routing (来自Cartoweb)
pgRouting示例 (来自GeoSalon的stinjia)
相关代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | -- 构建拓扑关系-- ALTER TABLE road ADD COLUMN source_id int; ALTER TABLE road ADD COLUMN target_id int; ALTER TABLE road ADD COLUMN edge_id int; -- next line is to work around a pgRouting bug in update_cost_from_distance (fixed in latest CVS) ALTER TABLE road RENAME id TO id_old; SELECT assign_vertex_id('road', 0.001); -- 重复检查-- SELECT * FROM (SELECT source_id, target_id, COUNT(*) AS c FROM road GROUP BY source_id, target_id ORDER BY c) AS foo WHERE foo.c = 2; -- 删除重复的列-- CREATE TABLE doublons AS SELECT * FROM road WHERE gid IN (SELECT gid FROM (SELECT DISTINCT ON (source_id, target_id) source_id, gid FROM road) AS doublon); DELETE FROM road; INSERT INTO road (SELECT * FROM doublons); DROP TABLE doublons; -- 构建视图-- SELECT create_graph_tables('road', 'int4'); --用距离赋予权重 -- SELECT update_cost_from_distance('road'); -- 执行shortest_path命令-- SELECT * FROM shortest_path(' SELECT gid as id, source_id::integer as source, target_id::integer as target, length(the_geom) as cost FROM road', 1, 15, TRUE, FALSE); |
Related posts:
About this entry
You’re currently reading “pgRouting,” an entry on Geoinformatics
- Published:
- 6.6.08 / 10上午
- Tags:
- pgRouting, PostGIS, PostgreSQL
Ajax ArcGIS Dreams Flex Geography Geoinformatics GeoRSS GIS Google Hardware Harvard History Jquery Linux Love Map MapServer NASA OGC OpenGIS OSGeo PHP Politics PostGIS PostgreSQL Python R Social Network SVG Ubuntu Web WebGIS Wordpress 中国 历史地理 宋朝 开源 新儒学 生活 遥感
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.














赵 博 (Bo Zhao),
参与或主持的项目
2 Comments
Jump to comment form | comments rss [?] | trackback uri [?]