1

I am using pgr_ksp for finding multiple paths for single source and destination. I am wondering if 'source' and 'target' in a roads table are unique or not. because when i am doing routing on my road network table and displaying their geometry on the basis of their 'target' value, it is giving me extra link roads everywhere. This is the query i am using

   SELECT pt.gid, seq AS route, id1 AS node,  id2 AS edge, cost, geom as line
   FROM pgr_ksp(
   'SELECT gid as id, source::int4, target::int4, length::float8 as cost FROM my_table',
    2087, 1428, 2, false
    )
    as di JOIN my_table pt
    ON di.id2 = pt.target

enter image description here

The red color is showing the output of the query. I know there is nothing wrong with the routing result but when i am trying to get the geometry, 'target' value is i think the only way to get it for display

enter image description here

I want the result as i am showing in the 2nd image with Red color, but right now i am getting extra road segments (shown in Green color) because i am choosing to display geometry from target value.

What can I do in order to get a better result?

2 Answers 2

3

You should use id3 of the result instead of id2 because id3 is the edge id according to http://docs.pgrouting.org/dev/src/ksp/doc/index.html

0
1

source and target attribute contain node ID's. Each node ID should be unique, but it can appear multiple times in source and target column, because a node can be the connecting point for more than one road link.

Depending of the direction (defined by the geometry) of the road link the node ID is source or target.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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