[pgrouting-users] Build the "right" direction in a network, from a fixed starting point

andy aborruso at gmail.com
Tue May 22 10:14:51 PDT 2018


Hi Vicky,
as usual you are fantastic. Thank you

On Tue, 22 May 2018 at 02:36, Vicky Vergara vicky at georepublic.de
<http://mailto:vicky@georepublic.de> wrote:


>
> ​SELECT ogc_fid as id, source, target, st_length(wkb_geometry)
> test1tmp-#                            as cost FROM linee;
>  id | source | target |       cost
> ----+--------+--------+------------------
>   1 |      1 |      2 | 1875.88794100276
>   2 |      3 |      1 | 1551.56248158866
>   3 |      1 |      4 | 1506.74402481746
>   4 |      4 |      5 | 1208.08883442544
>   5 |      2 |      6 | 1447.12212188142
> (5 rows)
>
> test1tmp=#SELECT * FROM pgr_dijkstraCost('SELECT ogc_fid as id, source,
> target, st_length(wkb_geometry)
>                            as "cost" FROM linee',1,ARRAY[2,3,4,5,6]);
>  start_vid | end_vid |     agg_cost
> -----------+---------+------------------
>          1 |       2 | 1875.88794100276
>          1 |       4 | 1506.74402481746
>          1 |       5 |  2714.8328592429
>          1 |       6 | 3323.01006288418
> (4 rows)
>
> From the results, vertex 3 is never reached (end_vid does not have a 3)
>
> WITH unreach_vertex AS
> (SELECT id FROM linee_vertices_pgr LEFT JOIN pgr_dijkstraCost('SELECT
> ogc_fid as id, source, target, st_length(wkb_geometry)
>                            as "cost" FROM linee',1,ARRAY[2,3,4,5,6])  ON
> (end_vid = id) WHERE id !=1 AND end_vid IS NULL)
> UPDATE  linee set source = target, target = source WHERE source  IN
> (SELECT id FROM unreach_vertex);
> UPDATE 1
> test1tmp=# SELECT * FROM pgr_dijkstraCost('SELECT ogc_fid as id, source,
> target, st_length(wkb_geometry)
>                            as "cost" FROM linee',1,ARRAY[2,3,4,5,6]);
>  start_vid | end_vid |     agg_cost
> -----------+---------+------------------
>          1 |       2 | 1875.88794100276
>          1 |       3 | 1551.56248158866
>          1 |       4 | 1506.74402481746
>          1 |       5 |  2714.8328592429
>          1 |       6 | 3323.01006288418
> (5 rows)
>
>
> This is a presente for me and I see some light :)

But I was very interested to this your

I dont know your data, but suppose
id = 1, source = A, target = B, cost > 0, reverse_cost = -1 and that vertex
A is not reachable
then “manually” would be:
UPDATE TABLE foo set source = target, target = source WHERE source IS IN ()

I understood that it was possible to have a negative cost, for the edge 2
of my example and starting from my data (my shapefile). A sort of direct
way to have this negative cost.
Than to have that 3 was reacheable, but with negative cost. I’ve probably
misunderstood it and it’s not like that


> you still won me an explanation of :
>
> >  Please, try to find out what I am doing wrong. (your answer will help
> see your current level of understanding of pgRouting)
>
> I will do it, but probably I’m a little dumb.

Thank you again
​
-- 
___________________

Andrea Borruso
website: https://medium.com/tantotanto
38° 7' 48" N, 13° 21' 9" E, EPSG:4326
___________________

"cercare e saper riconoscere chi e cosa,
 in mezzo all’inferno, non è inferno,
e farlo durare, e dargli spazio"

Italo Calvino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20180522/77fbee8a/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: immagine.png
Type: image/png
Size: 16712 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20180522/77fbee8a/attachment-0001.png>


More information about the Pgrouting-users mailing list