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