我想创建一个基于 osm.pbf 文件的 pgrouting 集水区。使用 OSM2PO 导入 pbf 文件后,使用 pgrouting 计算集水区工作正常。但要获得更详细的结果,最好至少在 2 公里后分割所有较长的道路。用 PostGIS 分割线没问题,但这会破坏我的路由网络。是另一种添加更多顶点的方法吗?谢谢!
问问题
395 次
1 回答
0
事实上,您可以按照自己的喜好拆分道路线,然后通过 pgr_createTopology 和 pgr_analyzeGraph 重新创建您的道路图。我已经设法在 plpgsql 中使用以下函数来做到这一点
CREATE OR REPLACE FUNCTION public.__create_roads_graph(
tabname text)
RETURNS text
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
counter integer;
expr text;
vert_tab character varying;
r record;
BEGIN
expr := 'select count(*) as cnt from %s';
expr := format(expr, tabname);
counter := 0;
for r in execute expr
loop
counter = r.cnt;
end loop;
if counter = 0
then
return 'Cancel';
end if;
expr := 'update ' || tabname || ' set km = ST_Length(geom_way::geography)/1000';
execute expr;
expr := 'update ' || tabname || ' set kmh=(CASE WHEN class=1 THEN 90 WHEN class=2 THEN 60 WHEN class=3 THEN 30 WHEN class=4 THEN 10 ELSE 0 END)
WHERE kmh is null OR kmh < 1';
execute expr;
expr := 'update ' || tabname || ' set cost = km / kmh where cost is null or cost=0';
execute expr;
expr := 'update ' || tabname || ' set reverse_cost = km / kmh where reverse_cost is null or reverse_cost=0';
execute expr;
expr := 'update ' || tabname || ' set x1=ST_X(ST_StartPoint(geom_way)),
y1=ST_Y(ST_StartPoint(geom_way)),
x2=ST_X(ST_EndPoint(geom_way)),
y2=ST_Y(ST_EndPoint(geom_way))';
execute expr;
expr := format('select * from pgr_createTopology( %L, %s, %L, %L, %L, %L, %L, %s)',
tabname, 0.000001, 'geom_way', 'id', 'source', 'target', 'true', 'true');
execute expr;
vert_tab := tabname || '_vertices_pgr';
perform __bvv_recreate_vertices_table(vert_tab);
expr := format('insert into %s(id, cnt, the_geom) with RECURSIVE united as (SELECT source AS id, x1 AS x, y1 AS y
FROM %s UNION ALL select target AS id, x2 AS x, y2 AS y
FROM %s) select id, count(*) as cnt,
ST_SetSrid(ST_MakePoint(avg(x), avg(y)), 4326) from united group by id order by id',
vert_tab, tabname, tabname);
/*expr := format('select * from pgr_analyzeGraph( %L, %s, %L, %L, %L, %L)',
tabname, 0.000001, 'geom_way', 'id', 'source', 'target');*/
execute expr;
RETURN 'Ok';
END
您可以在拆分路段之前查看路线的外观 节点和路线在拆分之前
拆分并执行功能 _create_roads_graph 后,您可以看到线中心的附加节点,更改了节点的编号并且与之前的路线相同
于 2018-12-01T19:27:03.943 回答