0

I am beginner in this and would like some help with the pgr_astar(pgRouting).

I would like an example in SQL to generate route options using the "pgr_astar " of pgRouting, obstacles avoidance (Points) existing on a particular region of a map extracted roads open streetmap. This road map has been imported into the database with osm2pgrouting.

So far I just can extract the basic, what would be the shortest path to the algorithm as shown in the following example.

SELECT seq, id1 AS node, id2 AS edge, cost    FROM pgr_astar('SELECT gid AS id,
                         source::integer,
                         target::integer,
                         length::double precision AS cost,
                         reverse_cost
                         x1, y1, x2, y2
                    FROM ways',
                         12927, 
                         19932, 
                         true, 
                         false);

But what I need is to avoid Points as car crash, interdicted street, broken bridge, etc .. Could someone give me a guidance how to modify this in SQL above?

The image below shows my difficulty. If there were no obstacle, the shortest path would be the red, but exist is an obstacle (car crash) and so I have to propose another way.

enter image description here

1

The easiest way to prevent the route using a certain way is to exclude the specific road segment from the network.

In pgr_astar (as well as in many other pgRouting functions) the first argument is the SQL, that selects the road network data, in your case this is

'SELECT gid AS id,
     source::integer,
     target::integer,
     length::double precision AS cost,
     reverse_cost
     x1, y1, x2, y2
  FROM ways'

You can append a WHERE clause to the query, where you can exclude the road segments, that are not accessible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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