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 am trying to use pgrouting to get the shortest path. I executed the shortest_path function and in return I got the set of edges belonging to that shortest path. When I got the geometry for each edge and converted it human readable text I got the following

MULTILINESTRING((-92.934305 44.929345,-92.934328 44.928139,-92.934308 44.926226,-92.934319 44.92516))
MULTILINESTRING((-92.934238 44.931787,-92.934286 44.930361,-92.934305 44.929345))
MULTILINESTRING((-92.934236 44.931864,-92.934238 44.931787))
MULTILINESTRING((-92.934134 44.935015,-92.934164 44.934074,-92.934236 44.931864))
MULTILINESTRING((-92.937956 44.937121,-92.937841 44.936852,-92.937701 44.936568,-92.937556 44.936322,-92.937467 44.936207,-92.937198 44.935914,-92.936925 44.935716,-92.936455 44.93542,-92.936235 44.935309,-92.936002 44.93522,-92.935764 44.935147,-92.935386 44.935089,-92.935175 44.93507,-92.934134 44.935015))
MULTILINESTRING((-92.9431718 44.9378538,-92.9428863 44.9378357,-92.942582   44.9378192,-92.9422621 44.9377809,-92.9417434 44.9376672,-92.9409703 44.9373986,-92.9400963 44.9371441,-92.9395865 44.937061,-92.9391747 44.937033,-92.9386135 44.9370293,-92.937956 44.937121))
MULTILINESTRING((-92.9488376 44.937303,-92.9483702 44.9375247,-92.9479276 44.937655,-92.9474106 44.9377678,-92.946837 44.9378455,-92.9461359 44.9378605,-92.9431718 44.9378538))
MULTILINESTRING((-92.94894 44.937434,-92.9488376 44.937303))
MULTILINESTRING((-92.94894 44.937434,-92.949013 44.93739,-92.949371 44.937237,-92.949808 44.937075,-92.95064 44.936877,-92.9509356 44.9368451,-92.9512401 44.9368242,-92.951439 44.9368205,-92.952328 44.936802,-92.954138 44.936761))
MULTILINESTRING((-92.954138 44.936761,-92.954364 44.936757))

When I joined the points obtained above in the order given, the paths tend to overlap each other. As you can see above the point -92.934305 44.929345 repeats. Any suggestions?

Initially I was using just the start and end vertices of the edges but since that was causing this overlap issue, I opted to use this geometry feature as well but still it is the same. QGis seems to plot it fine and it has the same set of edges that I got.

share|improve this question
Well I just found out that the direction is important. So I was parsing like from first point to last. But it should have been like from last to first. The direction/order is different for different routes – rajan sthapit Jun 1 '12 at 18:03
In light of this comment, is there any question left here? – whuber Jun 1 '12 at 18:16
No, I think the issue is fixed. It is closed. Thanks everyone – rajan sthapit Jun 1 '12 at 19:57
up vote 1 down vote accepted

The direction of the linestring geometry is from source to target. Your path may return segments that should be traveled from target to source though. In that case you need to compare start and end point of each linestring and flip the geometry if they don't match.

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.