[pgrouting-users] Re: Pgrouting-users Digest, Vol 40, Issue 2

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, ECOSTRATIO, EREVERSE_COST(1-RATIO)
union all
select maxgid+2, NEWNODE, ETARGET, ECOST*(1-RATIO), EREVERSE_COST*RATIO

-Steve

I get lost on your 3rd step: “Create a temporary node”
How do you insert just a node? The “roads” table is made up of edges, so wouldn’t I need to insert an edge?

On Tue, Jan 10, 2012 at 10:26 AM, Steve Horn steve@stevehorn.cc 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, ECOSTRATIO, EREVERSE_COST(1-RATIO)
union all
select maxgid+2, NEWNODE, ETARGET, ECOST*(1-RATIO), EREVERSE_COST*RATIO

-Steve

I get lost on your 3rd step: “Create a temporary node”
How do you insert just a node? The “roads” table is made up of edges, so wouldn’t I need to insert an edge?

You “create” a node, that you know the “source” and “target” ID of the edge. This ID may not exist yet.

Daniel


Georepublic UG & Georepublic Japan
eMail: daniel.kastl@georepublic.de
Web: http://georepublic.de

On 1/9/2012 8:26 PM, 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)

Right as Daniel noted, so the NEWNODE is just a number that would be MAX_NODE_ID+1 If you have the vertices_tmp then you can get this number with

select max(id)+1 as newnode from vertices_tmp;

    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 where the_geom && <bbox>
    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

This query is providing all the edges in the "roads" table and adding two additional edges for the split nearest edge with NEWNODE at you location.

-Steve

    -Steve

I get lost on your 3rd step: "Create a temporary node"
How do you insert just a node? The "roads" table is made up of edges, so
wouldn't I need to insert an edge?

_______________________________________________
Pgrouting-users mailing list
Pgrouting-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/pgrouting-users