I would like to calculate the shortest path with dijkstra algorithm.
sample query SELECT seq, id1 AS node, id2 AS edge, cost FROM pgr_dijkstra(' SELECT gid AS id, source::integer, target::integer, length::double precision AS cost FROM ways', 30, 60, false, false);
I imported an osm map, it has proper network. The name of the table is at_2po_4pgr
, colums are id, osm_id, osm_name, osm_meta, osm_source_id, osm_target_id, clazz, flags, source, target, km, kmh, cost, reverse_cost, x1, y1, x2, y2, geom_way
.
in result I would like to see the shortest path and streets name in a row where route was planning.
Thanks
Answer
You best start with the workshop, and especially look at the chapter, which explains how to write a simple plpgsql wrapper function to return additional attributes such as street name for example.
A query might look like this then:
SELECT seq, id1 AS node, id2 AS edge, cost, b.the_geom, b.osm_name FROM pgr_dijkstra('
SELECT id,
source::integer,
target::integer,
length::double precision AS cost
FROM at_2po_4pgr',
30, 60, false, false) a LEFT JOIN at_2po_4pgr b ON (a.id2 = b.id);
You really just have to change a few table/attribute names.
No comments:
Post a Comment