Prepare routing table for A-Star

Add x1, y1 and x2, y2 column

ALTER TABLE victoria ADD COLUMN x1 double precision;
ALTER TABLE victoria ADD COLUMN y1 double precision;
ALTER TABLE victoria ADD COLUMN x2 double precision;
ALTER TABLE victoria ADD COLUMN y2 double precision;
UPDATE victoria SET x1 = x(startpoint(the_geom));
UPDATE victoria SET y1 = y(startpoint(the_geom));
UPDATE victoria SET x2 = x(endpoint(the_geom));
UPDATE victoria SET y2 = y(endpoint(the_geom));

Note: "endpoint()" function fails for some versions of PostgreSQL (ie. 8.2.5, 8.1.9). A workaround for that problem is using the "PointN()" function instead:

UPDATE victoria SET x1 = x(PointN(the_geom, 1));
UPDATE victoria SET y1 = y(PointN(the_geom, 1));
UPDATE victoria SET x2 = x(PointN(the_geom, NumPoints(the_geom)));
UPDATE victoria SET y2 = y(PointN(the_geom, NumPoints(the_geom)));

Run Shortest Path A-Star query

shortest_path_astar( sql text, 
		   source_id integer, 
		   target_id integer, 
		   directed boolean, 
		   has_reverse_cost boolean ) 

(Source and target IDs are node IDs.)

A-Star core function

SELECT * FROM shortest_path_astar('
		SELECT gid as id, 
			 source::integer, 
			 target::integer, 
			 length::double precision as cost, 
			 x1, y1, x2, y2
			FROM victoria', 
		238, 1455, false, false); 

Wrapper function with bounding box

SELECT gid, AsText(the_geom) AS the_geom
	FROM astar_sp_delta('victoria', 238, 1455, 3000);