[pgrouting-users] dijkstra_sp result order
Stephen Woodbridge
woodbri at swoodbridge.com
Fri Nov 13 15:39:55 EST 2009
Hi Julien,
Welcome to the community.
Julien-Samuel Lacroix wrote:
> Hi,
>
> I'm trying to use the wrapper functions dijkstra_sp and astar_sp to find
> the shortest path between to points. However the order of the output
> seems to be wrong.
> The following:
>
> SELECT * FROM astar_sp( 'fcmqrouting19', 80, 3667)
Try:
SELECT id, gid, astext(the_geom)
FROM astar_sp( 'fcmqrouting19', 80, 3667);
Since the results are edges you need to check if the edge needs to be
ordered from-to or to-from. So to order the edges you need to do
something like this pseudo-code:
Loop through edges in results
if first edge then
if edge.start == next.start or edge.start == next.end then
edge = edge.reverse // now the first edge is in the correct order
end
else
if last.end == edge.end then
edge = edge.reverse
end
end
last = edge
end loop
I have not seen the problem you mention below.
-Steve Woodbridge
> returns an un-ordered list of feature (The first line segment in my path
> come in third place in the result set for example):
>
> id; gid; the_geom
> 1; 617; "010...4640"
> 2; 513; "010...640"
> 3; 121; "010...4640"
> 4; 618; "0102...640"
> 5; 2; "01020...40"
> 6; 4581;"0102...640"
>
> If I use shortest_path (both astar or dijkstra) functions the order of
> gid returned is:
> 121, 513, 617, 2, 618, 4581
>
> My questions are:
> Is this a known bug?
> Is there a way to keep the order of my results and still have the "id"
> column containing the row number (from 1 to 6 in my example)?
>
> Best regards,
> Julien
>
More information about the Pgrouting-users
mailing list