TransWikia.com

How to find shortest route between ANY source for ALL targets?

Geographic Information Systems Asked on January 6, 2021

I have a list of starting points and a list of target points for pgRouting. I want to calculate the shortest path for every pair of [source,target]. I am using a subselect to pass an array of node id’s to the pg_dijkstra() function:

SELECT seq, id1 AS node, id2 AS edge, cost, linestring
  FROM pgr_dijkstra(
    'SELECT id::integer, source::int4, target::int4, st_length(linestring)::float8 as cost FROM my_ways',

    --source nodes
    array(
        select 
            target as "source_ids"
        from 
            my_ways
        where
            id in (
                select gid from my_sources
            )
    ), 

    --target nodes
    array(
        select 
            target as "target_ids"
        from 
            my_ways
        where
            id in (
                select objectid from my_targets
            )
    ),
    false, 
    false
  ) as di
  JOIN atene_4377.ways_atene_4377 ways
  ON di.id2 = ways.id ;

But when I do so I get the following error message:

ERROR: function pgr_dijkstra(unknown, integer[], integer[], boolean, boolean) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.

However, if I replace the arrays with single node ids, the algorithm works fine. So there is something wrong about how I pass the array to the function. Any ideas how to fix this?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP