<div dir="ltr"><div><div>Hi Emmanuel<br><br></div>If you want to make the old workshop works on pgRouting 2.0 <br><br><br><div class="gmail_extra"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class=""><div class="h5"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<br>
|<?php<br>
<br>
// Database connection settings<br>
define("PG_DB" , "routing");<br>
define("PG_HOST", "localhost");<br>
define("PG_USER", "postgres");<br>
define("PG_PORT", "5432");<br>
define("PG_PASSWD", "*******");<br>
define("TABLE", "eastlegon");<br>
<br></div>
$counter= $pathlength= 0;<div><br>
<br>
// Retrieve start point<br>
$start= split('',$_REQUEST['startpoint']);<br></div>
$startPoint= array($start[0], $start[1]);<div><br>
<br>
// Retrieve end point<br>
$end= split('',$_REQUEST['finalpoint']);<br></div>
$endPoint= array($end[0], $end[1]);<div><br>
<br>
// Find the nearest edge<br>
$startEdge= findNearestEdge($startPoint);<br></div>
$endEdge= findNearestEdge($endPoint);<div><br>
<br>
// FUNCTION findNearestEdge<br>
function findNearestEdge($lonlat) {<br>
<br>
// Connect to database<br></div>
$con= pg_connect("dbname=".PG_DB." host=".PG_HOST." user=".PG_USER." password=".PG_PASSWD);<br>
<br>
$sql= "SELECT gid, source, target, the_geom,<div><br>
distance(the_geom, GeometryFromText(<br>
'POINT(".$lonlat[0]."".$lonlat[1].")', 4326)) AS dist<br>
FROM ".TABLE."<br>
WHERE the_geom && setsrid(<br>
'BOX3D(".($lonlat[0]-200)."<br>
".($lonlat[1]-200).",<br>
".($lonlat[0]+200)."<br>
".($lonlat[1]+200).")'::box3d, 4326)<br>
ORDER BY dist LIMIT 1";<br>
<br></div>
$query= pg_query($con,$sql);<div><br>
<br>
$edge['gid'] = pg_fetch_result($query, 0, 0);<br>
$edge['source'] = pg_fetch_result($query, 0, 1);<br>
$edge['target'] = pg_fetch_result($query, 0, 2);<br>
$edge['the_geom'] = pg_fetch_result($query, 0, 3);<br>
<br>
// Close database connection<br>
pg_close($con);<br>
<br>
return $edge;<br>
}<br>
<br>
// Select the routing algorithm<br>
switch($_REQUEST['method']) {<br>
<br>
case 'SPD' : // Shortest Path Dijkstra<br>
<br></div>
$sql= "SELECT rt.gid, AsText(rt.the_geom) AS wkt,<div><br>
length(rt.the_geom) AS length, ".TABLE.".id<br>
FROM ".TABLE.",<br>
(SELECT gid, the_geom<br>
FROM dijkstra_sp_delta(<br>
'".TABLE."',<br>
".$startEdge['source'].",<br>
".$endEdge['target'].",<br>
3000)<br>
) as rt<br>
WHERE ".TABLE.".gid=rt.gid;";<br>
break;<br></div></blockquote></blockquote></div></div></div></div></blockquote><div> <br> Here you have to change the function to pgRouting 2.0 using pgr_dijkstra function as show below;<br><br> case 'SPD' : // Shortest Path Dijkstra<br>
$sql = "SELECT w.gid, AsText(w.the_geom) AS wkt,<a href="http://w.name">w.name</a>, ST_length(w.the_geom) AS length, w.gid FROM ".TABLE." w,<br> (SELECT seq, id1 AS node, id2 AS edge,cost FROM pgr_dijkstra('<br>
SELECT gid AS id,source::integer,<br> target::integer,<br> length::double precision AS cost <br> FROM ".TABLE."',<br> ".$startEdge['source'].",<br>
".$endEdge['target'].", false, false) )as rt where w.gid=rt.edge;";<br><br> break;<br> </div><br></div><br><div class="gmail_extra">It is works on my Computer using this code.<br>
<br></div><div class="gmail_extra">Best,<br></div>Bomp<br clear="all"><br>-- <br><div dir="ltr"><div>$B"#"""#"""#"""#"""#"""#"""#"""#"""#(B<br>Graduate School for Creative Cities<br>Urban Informatics<br>GIS Laboratory <br>Osaka City University $BBg:e;TN)Bg3X(B <br>
Sittichai Choosumrong<br>TEL<font color="#17365d"> <span>+81-80-3812-2102</span><span dir="ltr"><span dir="ltr" title="Call this phone number in Japan with Skype: +819065588559"><span></span><span title="Skype actions"><span> </span> </span><span><span> </span></span></span></span></font><br>
$B"#"""#"""#"""#"""#"""#"""#"""#"""#(B</div></div>
</div></div></div>