pgRouting是一个为PostgreSQL和PostGIS提供路由功能的开源库,它支持复杂的图论算法,用于在地理网络中进行最短路径搜索。以下是pgRouting的一些应用实例。
注意事项:
1、路网表中的id、source、target必须是int类型,否则创建拓扑关系会报错
创建拓扑关系:
SELECT pgr_createTopology('beijing_road_all',0.000002,'geom','pid','source_id','target_id');
执行过程如下:
执行完成:
--获取最短路径
SELECT * FROM pgr_dijkstra('SELECT pid AS id,source,target,length AS cost FROM beijing_road_all', 846736,335245,FALSE);
--裁剪
SELECT st_astext(st_linesubstring(st_geomfromtext('LINESTRING (116.383555501302 39.9708582899306,116.384524468316 39.9708976236979)'),0, ST_LineLocatePoint('LINESTRING (116.383555501302 39.9708582899306,116.384524468316 39.9708976236979)','POINT(116.3836 39.97083)')));