zoukankan      html  css  js  c++  java
  • Introduction to PostGIS 之使用Shortest Path Shooting Star 对有向道路的路径计算

         闲暇之余了解了下pgrouting对有向图的路径计算

         正好官网有篇介绍处理“one—way”情况下的路径计算:http://www.pgrouting.org/docs/howto/oneway.html  

         下面我就一份无锡地图来做下相关学习:

    1.      对软件的安装这就不做介绍了,使用的软件版本和Introduction to PostGIS 之最优路径 是一样的。
    2.      我手上的地图数据是tab格式的为了保证导入数据库数据的完整性,我把tab转shp后在导入数据库。(tab转shp:mapinfo软件自带一个转换工具如下图)
    3.      把转换后的shp数据加载到ArcMap中入下图:
    4.      因为要在数据库中对道路建立拓扑关系,为了简单处理,这里我把主要道路、次要道路和立交桥合为一个图层(国道暂不考虑)。使用toolbox中的Merge工具合并这几个图层:

    5.       合并图层后进行拓扑处理:

      这个处理只是泛泛的处理,里面还有一些要根据实际情况再做处理如:

    6.      数据处理好后我们就可以导入数据库了,这里我使用QGIS来导入:
    7.     导入数据库后我重命名为roads_polyline_merge表,接下来的步骤就比较重要了。
    8.     向表中添加字段:
      1 ALTER TABLE wuxirouting.roads_polyline_merge ADD COLUMN source integer;
      2 ALTER TABLE wuxirouting.roads_polyline_merge ADD COLUMN target integer;
      3 ALTER TABLE wuxirouting.roads_polyline_merge ADD COLUMN cost double precision;
      4 ALTER TABLE wuxirouting.roads_polyline_merge ADD COLUMN reverse_cost double precision;
      5 ALTER TABLE wuxirouting.roads_polyline_merge ADD COLUMN x1 double precision;
      6 ALTER TABLE wuxirouting.roads_polyline_merge ADD COLUMN y1 double precision;
      7 ALTER TABLE wuxirouting.roads_polyline_merge ADD COLUMN x2 double precision;
      8 ALTER TABLE wuxirouting.roads_polyline_merge ADD COLUMN y2 double precision;
    9.     下面对这个字段赋值 为source和target赋值:
      set search_path = public,wuxirouting;
      SELECT assign_vertex_id('roads_polyline_merge',.00001,'the_geom','gid');
          为其余字段赋值:
      UPDATE wuxirouting.roads_polyline_merge SET cost = st_length(the_geom)*10000;
      UPDATE wuxirouting.roads_polyline_merge SET reverse_cost = 1000000;
      UPDATE wuxirouting.roads_polyline_merge SET x1 = st_x(st_startpoint(the_geom));
      UPDATE wuxirouting.roads_polyline_merge SET y1 = st_y(st_startpoint(the_geom));
      UPDATE wuxirouting.roads_polyline_merge SET x2 = st_x(st_endpoint(the_geom));
      UPDATE wuxirouting.roads_polyline_merge SET y2 = st_y(st_endpoint(the_geom));
    10.     执行一下路径查询并存入一个表中以便Qgis中显示:
      SELECT gid,the_geom,edge_id 
      into wuxirouting.routing
      FROM shortest_path_astar('SELECT gid as id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM wuxirouting.roads_polyline_merge',149,158, true,true)as r,wuxirouting.roads_polyline_merge as w
      where r.edge_id=w.gid


  • 相关阅读:
    编译pypcap
    python输出重复字符串的简单办法
    Python天天美味(1) 交换变量(转)
    Python天天美味(4) isinstance判断对象类型(转)
    Python天天美味(2) 字符遍历的艺术(转)
    Python天天美味(3) 字符转换(转)
    Python天天美味(5) ljust rjust center(转)
    Python天天美味(6) strip lstrip rstrip(转)
    Python天天美味(10) 除法小技巧(转)
    Python标准库12 数学与随机数 (math包,random包)(转)
  • 原文地址:https://www.cnblogs.com/shitao/p/2256178.html
Copyright © 2011-2022 走看看