0

I am trying to find a way to route from the closest point on a linestring to my current location (lat, long). So far I am able to get the shortest path but it starts from the very beginning of the linestring (aka source). I am using prg_trsp http://docs.pgrouting.org/2.0/en/src/trsp/doc/index.html because it has a feature to specify the starting position along the linestring. I am able to correctly calculate the distance along the linestring and pass the values to the function but cannot figure out how to use the results from the function (pgr_costResult[]) to specify where the route should start (partially along the closest linestring).

I have a feeling I am doing something wrong with the join when I go to join the results from the routing algorithm to my edge table to get the geometry because when I join it uses the edge table's full geometry and not segments. Although, looking at the documentation, I don't see where you get a returned segment from the routing function.

Below is a screenshot of what I am trying to do (red line) and what I have (blue line) the point is the current location. The red line comes from using the pgrouting plugin in qgis with the trsp(edge) selection.

SELECT st_linemerge(edgeTable.geom_way) FROM pgr_trsp('SELECT id, source, target, cost FROM edgeTable', 
    (SELECT id FROM origin),
    (SELECT * FROM sourcePos),
    (SELECT id FROM destination),
    (SELECT * FROM destPos),
    false, false) AS shortestPath
    JOIN edgeTable ON shortestPath.id2 = edgeTable.id;

origin is the id of the starting route

sourcePos is how far along the linestring to offset

destination is the id of the end linestring

destPos is the fraction of the end linestring

all as specified here: http://docs.pgrouting.org/2.0/en/src/trsp/doc/index.html

enter image description here

1 Answer 1

1

You're referencing a very old version of pgRouting, which is now available as version 2.6: http://docs.pgrouting.org/

In newer versions of pgRouting you will find the withPoints functions, which provide the functionality you are looking for: http://docs.pgrouting.org/latest/en/withPoints-family.html#withpoints

You need to select the correct function based on the algorithm you want to use.

2
  • I also need to be able to specify restrictions like eliminating an edge (making the cost so high that the algorithm routes around it). Can this be done with the "withPoints" functions?
    – Logan M
    Apr 6, 2018 at 19:24
  • Also, it may be worth mentioning that when I run the pgRouting plugin and select trsp(edge) this gives me the value that I want - provides the red line as seen in the above screenshot.
    – Logan M
    Apr 6, 2018 at 19:36

Your Answer

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

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