[pgrouting-users] Inserting Nodes Into a Network
Stephen Woodbridge
woodbri at swoodbridge.com
Mon Jan 9 11:16:21 EST 2012
On 1/9/2012 10:05 AM, Steve Horn wrote:
> Hello all!
>
> I am creating drive time radii (or isochrones) by allowing the user to
> click on a map surface and entering a number of minutes.
>
> Using the driving_distance function in pgrouting I am able to get very
> close to a good solution, but it is somewhat limited in that you can
> only route from node to node (vertex to vertex). In order to improve the
> accuracy, I thought I would try to insert a new node/vertex as close as
> possible to the coordinates that my user clicked. That way my start node
> would always be as accurate as it can be.
>
> Has anyone done this? I'm not sure I understand the assign_vertex_id
> function and how the graph is constructed well enough to come up with a
> solution myself.
>
> Any help or direction is appreciated!
What you would want to do in this case is:
1. take you position and find the nearest edge to that location (EID,
ESOURCE, ETARGET, ECOST, EREVERSE_COST)
2. compute the ratio of distance along that edge (RATIO)
3. then add a create a temporary node at that location (NEWNODE)
4. then add edges from the temp node to each of the end points to that
edge, paying attention to oneway-ness of that edge and assigning costs
as a ratio of the original cost.
So select edges for your query might look like and you would pass
NEWNODE as the starting node.
select gid, source, target, cost, reverse_cost from roads
union all
select maxgid+1, ESOURCE, NEWNODE, ECOST*RATIO, EREVERSE_COST*(1-RATIO)
union all
select maxgid+2, NEWNODE, ETARGET, ECOST*(1-RATIO), EREVERSE_COST*RATIO
-Steve
More information about the Pgrouting-users
mailing list