Forum #18 - Topic #70 - Message List
Hi,
First of all sorry for asking another question again :( But I am really interested in this project and trying alot of functions :)
I am trying to play a bit with the Shooting Star Query, since I need it for one-ways.
I am trying this query : SELECT gid, the_geom
FROM shootingstar_sp('streets',
give_source('POINT(640905 225230)',1000,200), give_target('POINT(640982 225439)',1000,200), 2000,'length',true,true);
and also tried this query : select rt.gid, rt.the_geom, length(rt.the_geom), streets.gid from streets, (select gid, the_geom from shootingstar_sp( 'streets', give_source('POINT(640905 225230)',1000,200), give_target('POINT(640982 225439)',1000,200), 5000, 'length', true, true) )as rt
For half of the results both edge_ids are the same, however when I project the result on a shapefile then on QGis on my map, the points where the route should start and end are FAR from the points I selected.
The functions give_source and give_target are functions I gave to transfrom the Point to the source colum and this is the function : -- Function: give_source(text, integer, integer)
-- DROP FUNCTION give_source(text, integer, integer);
CREATE OR REPLACE FUNCTION give_source(text, integer, integer)
RETURNS integer AS
$BODY$
DECLARE
pojnt ALIAS FOR $1; box ALIAS FOR $2; dist ALIAS FOR $3;
r_source INTEGER;
BEGIN
SELECT source INTO r_source FROM streets s WHERE
( the_geom && expand (pointfromtext(pojnt),box) and distance (s.the_geom , pointfromtext(pojnt)) < dist )
ORDER BY distance (s.the_geom , pointfromtext(pojnt)) ASC LIMIT 1;
RETURN r_source;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION give_source(text, integer, integer) OWNER TO yancho;
I know it should be something stupid that I am doing, but really am out of ideas why it is not working. For sure the routing is being done well, but the start / end points are wrong, so it should be something from the give_source / give_target problem. BTW I used these two functions for my astar_sp_delta testing and it worked perfectly :
SELECT gid, AsText?(the_geom) AS wkt
FROM astar_sp_delta(
'streets', (select give_source('POINT(640905 225230)',1000,200), (select give_target('POINT(640982 225439)',1000,200), 3000 );
";
Any ideas will be extremely appreciated and keep up the good work :)
-
Message #265
I am including this info maybe it helps you better tackle this problem :
As you can see on the paste here : http://yancho.pastebin.com/f7f44a0c2
The first result row of astar_sp_delta is : 40617;"MULTILINESTRING((640920.707155369 225441.381903503,640919.710413482 225419.024734874,640904.400352 225231.230885577))"
.. Which is very near the POINT : POINT(640905 225230),
However the first result row of shootingstar_sp is : 791;"MULTILINESTRING((629357.137492173 222486.61416491,629357.137492172 222526.524103276))" followed by these two :
47462;"MULTILINESTRING((629357.137492172 222526.524103276,629355.842055444 222559.004436553))" 44423;"MULTILINESTRING((629355.842055444 222559.004436553,629354.394306192 222605.962730528))"
Which shows clearly how far it is from the starting point : POINT(640905 225230)
Also I tried this function :
SELECT * FROM shortest_path_shooting_star('
SELECT gid as id,
source::integer, target::integer, length::double precision as cost, rcost::double precision as reverse_cost, x1, y1, x2, y2, rule, to_cost
FROM streets',
give_source('POINT(640905 225230)',1000,200), give_target('POINT(640982 225439)',1000,200),
false,true);
Highted and pasted here : http://yancho.pastebin.com/f7a2f7e2b
Which is giving me these 3 rows as my first resultset : 13065;791;39.9099383660941 13066;47462;32.5061564333317 21733;44423;46.9806061157797
Which have the same gid as the first 3 resultset given from shootingstar_sp .. so it is quite obvious I am giving the functions the wrong starting location / ending .. any one can shed some light on what I should fix please?
Thanks and regards
Matthew
yancho11/27/07 02:02:52 -
Message #271
Today I have made some improvements. But am still not satisfied with the outcome.
This is the query I have in my routing.php :
$source = "select give_source('POINT(".$sp.")',1000,200)"; $target = "select give_target('POINT(".$ep.")',1000,200)" ; $sql = "
SELECT gid, astext(the_geom) as wkt, length(the_geom) AS length FROM shootingstar_sp ('streets',
( select gid from streets where source = ( $source ) limit 1 )
,
( select gid from streets where target = ( $target ) limit 1
)
, 5000, 'length', true, true );
";
Highlighted here : http://yancho.pastebin.com/f5e820cd7
This query is resulting in this image : http://solutions-lab.net/thesis/routing1.jpg
As one can see, it is starting early and finishing late. How can I fix this problem please?
This is a copy/paste of the XML : http://yancho.pastebin.com/d5c63bed6 and can be viewed here : http://yancho.no-ip.org/~yancho/routing.php?startpoint=643206.15625%20223290.03125&finalpoint=644186.625%20224672.84375&method=SPA®ion=streets&srid=-1&_=
Any improvements will be extremely appreciated! :)
Thanks beforehand!
Matthew
yancho12/04/07 19:45:48

