1

I want to combine the following 3 commands (and eventually other ones such as functions from matching.sql right after...):

routing=> select source as s from ways where gid=10213;
  s   
------
 8217
(1 row)

routing=> select target as t from ways where gid=64552;
   t   
-------
 44926
(1 row)

routing=> insert into test(the_geom) select ST_UNION(the_geom) from dijkstra_sp('ways', 8217, 44726);
INSERT 0 1

So I tried many things that look like

WITH depart AS (SELECT source AS s FROM ways WHERE gid=10213), 
    arrivee AS (SELECT target as t FROM ways where gid=64552) 
INSERT INTO test(the_geom) SELECT ST_UNION(the_geom) 
FROM dijkstra_sp('ways', depart.s, arrivee.t);

but any of my experiments worked; any idea someone, please??

Edit: Thanks to dkastl, I wrote the following, certainly not optimized but still working one-line function to get a path from coordinates :

INSERT INTO test(the_geom) SELECT ST_UNION(the_geom) 
    FROM dijkstra_sp('ways', 
        (SELECT source from ways 
where distance(the_geom, geometryFromText('POINT(5.697 45.27433)', 4326)) = 
        (select min(distance(the_geom, GeometryFromText('POINT(5.697 45.27433)', 4326))) as dist from ways where the_geom && setsrid('BOX3D(0 30, 12 60)'::box3d, 4326))), 
        (SELECT source 
            from ways 
                where distance(the_geom, GeometryFromText('POINT(5.05169 45.0482)', 4326)) 
                = (select min(distance(the_geom, GeometryFromText('POINT(5.05169 45.0482)', 4326))) as dist 
                        from ways 
                        where the_geom && setsrid('BOX3D(0 30, 12 60)'::box3d, 4326)
                    )
         )
 );
2

This should work:

INSERT INTO test(the_geom) SELECT ST_UNION(the_geom) 
    FROM dijkstra_sp('ways', 
        (SELECT source FROM ways WHERE gid=10213)::integer, 
        (SELECT target FROM ways WHERE gid=64552)::integer
    );

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.