Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to plot the shortest path returned by pgRouting. However, I am having some issues. Sometimes it comes out a mess.

I have just joined the coordinates of the edges returned by the shortestpath query. However as mentioned in this link http://underdark.wordpress.com/2011/02/07/a-beginners-guide-to-pgrouting/ it says that it uses the necessary geometries. The path is plotted fine by QGIS. It is mentioned in this line

Therefore, we’ll join the results of the previous query with the network table containing the necessary geometries. Suggestions?


SELECT x1,y1,x2,y2 
FROM shortest_path('
   SELECT id,
          source::integer,
          target::integer,
          cost::double precision 
   FROM at_2po_4pgr',
   $start_node, $end_node, false, false) 
INNER JOIN at_2po_4pgr 
ON edge_id = at_2po_4pgr.id. 

I used osm2po to generate the at_2po_4pgr table which contains the edges, their start and end vertices and other information.

I send the bunch of returned x1,y1,x2,y2 and then join these coordinates. Sometimes the path looks fine but sometimes it's a mess. The path looks fine when I use QGIS. But they have different implementation I guess.


Actually my question is, is it enough to send the start and end points of the edges returned by the query and then join these start and end points of each edge by straight line? Or I am supposed to use the geometry given by multilinestring which I have less idea about


I am trying to actually figure out what the "geom_way" column exactly represents and how to use that in my case. I created a network topology and persisted it to postgresql database using osm2po tool for a certain region. Now I am using pgrouting on it to find the shortest route. I am not sure how this column is used by qgis to display the route. It's just a bunch of number, how can I use it in my case?

I am actually using gpx format file to transfer the shortest path. How can I exploit this geometry and send that information in gpx so that it is displayed nicely.

share|improve this question
    
Please try to increase your accept rate. With an accept rate of 0% you are less likely to receive good answers. By accepting answers, you can give back to those people who donated their time to help you. –  underdark May 30 '12 at 16:56
add comment

1 Answer

up vote 0 down vote accepted

Based on this old pgRouting bug report: ftp://ftp.remotesensing.org/pgrouting/forum/pgrouting.postlbs.org/ticket/159.html, I would say that joining the routing results with the network table returns the rows in their natural order (the way they were inserted to the table) instead of the routing order. The advise was:

To order shortest path search results please try to use wrapper functions - they allow you to order your result by id field.

Update:

The problem you might have run into is that start/end points are defined by the digitizing direction and not by the direction the link is traversed in the routing result.

eg. two links might run in route direction, one in the opposite direction:

      Link1                      Link2                            Link3
|-------------------------><-------------------------------||----------------->
1                         22                               11                 2

Note: pgRouting does not switch the directions of links!!!

You have to ensure that you are sending the points in the correct order so that x2/y2 of Link1 == x1/y1 of Link 2 and so on.


I am not sure how "geom_way" column is used by qgis to display the route. It's just a bunch of number, how can I use it in my case?

What you are seeing is the serialization of the geometry object. If you want something human-readable, I'd suggest wrapping "geom_way" in asText()

select asText("geom_way")
share|improve this answer
    
I don't think that is the issue.I had the issue before but after my join the rows were returned in the order of the shortest path. That is not the case I guess. The thing is the path is rendered properly for some while for some it's a total mess –  rajan sthapit May 30 '12 at 20:39
    
If the final route is a mess, the order hast to get jumbled somewhere. Without more info, you'll have to debug it yourself. –  underdark May 30 '12 at 20:52
    
No actually my question is, is it enough to send the start and end points of the edges returned by the query and then join these start and end points of each edge by straight line? Or I am supposed to use the geometry given by multilinestring which I have less idea about –  rajan sthapit May 30 '12 at 20:55
    
That depends. For some applications it would be enough to have straight lines to get a general idea of the route. Others will need detailed geometries. The problem you might have run into is that start/end are defined by the digitizing direction and not the direction the link is traversed in the route. That's another potential problem source. –  underdark May 30 '12 at 21:00
    
I didn't get it what you mean by digitizing the direction. Pgrouting returns an ordered list of edges that define the shortest path. How can I actually use that geometry feature. I am not even sure how it is generated and how to interpret it while plotting the results –  rajan sthapit May 31 '12 at 3:25
show 1 more comment

Your Answer

 
discard

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.