Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)
                    )
         )
 );

Thanks!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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
    );
share|improve this answer
    
Thank you dkastl! –  Aname Mar 26 '12 at 12:53
    
@Aname The best way to thank someone is to upvote the answer and accept it. –  underdark Mar 26 '12 at 14:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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