Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a query which i use to find a route between two points . Even though the route is displayed good on the map the order i get from pgrouting is wrong the query is this one

SELECT rt.gid, ST_AsGeoJSON(rt.the_geom) AS geojson, 
                   length(ST_transform(rt.the_geom,3785))as meters,x1,x2,y1,y2,name, ways.gid 
                FROM ways, 
                    (SELECT gid, the_geom 
                        FROM dijkstra_sp_delta(
                   ) as rt 
              WHERE ways.gid=rt.gid;

do you know any way to take the segments of the route in right order ?

Thanks in advance

share|improve this question
I have found this thread here which seems to have the same problem as me… What i don't understand is why the segment is loading in reverse and how can i understand that . Also i can't understand the given solution so a little more detailed explanation would be much apriciated – john Oct 3 '12 at 16:58

Although you are using a different routing function but problem was the same I was facing and I hope this can help you out

try to order your result by sequence of your routing table. by doing that you will get your road segments in right order this is what i am doing this:

SELECT pt.gid, seq, id1 AS node, id2 AS edge, cost, geom as line FROM pgr_dijkstra('SELECT 
  gid as id, 
  shape_leng::float8 as cost
  FROM my_table',

1543, 186, false, false ) as di JOIN my_table pt ON di.id2 = pt.gid ) order by seq But when I tried to draw this route on the map for my mobile app (Android) as a complete route, road segments where not in the right order. Then I merged all the road segments as a single feature by using


and the result was perfect

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.