<div dir="ltr"><div>hi,</div><div>i hope this code can help you. it s not complete and not optimised</div><div>///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</div>
<div><html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>"></div><div><br></div><div><?php</div><div><br></div><div>if ( extension_loaded('pgsql') != 1)</div><div>
{</div><div> switch (PHP_OS)</div><div> {</div><div><br></div><div> case "WINNT": if (!extension_loaded('pgsql')) dl("php_pgsql.dll");</div><div> break;</div><div> default: if (!extension_loaded('pgsql')) dl("php_pgsql.so");</div>
<div> break;</div><div> }</div><div>}</div><div><br></div><div>//=========================================</div><div><br></div><div>// includes du fichier fonctions</div><div>//=========================================</div>
<div>require 'connexion.php';</div><div><br></div><div><br></div><div>function ConvertTemps ($temps) {</div><div>if ($temps<60) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps=round($temps,0);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>$msg= $temps.'s';</div><div>}</div><div>if ($temps>=60 && $temps<3600) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps=round($temps,0);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps_s=$temps % 60;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps_mn = ($temps - $temps_s)/60;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$msg= $temps_mn.'mn'.$temps_s.'s';</div>
<div>}</div><div>if ($temps>=3600) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps=round($temps,0);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps_s=$temps % 3600;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps_h=($temps - $temps_s)/3600;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if ($temps_s>=60) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$temps_s=$temps % 60;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>$temps_mn = ($temps - $temps_s)/60;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$msg= $temps_h.'h'.$temps_mn.'mn'.$temps_s.'s';</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$msg= $temps_h.' h00mn '.$temps_s.'s';</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div>
<div>}</div><div>return $msg;</div><div>}</div><div><br></div><div>function ConvertDistance ($longueur) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$longueur=round($longueur,0);</div><div>if ($longueur>=1000) {</div>
<div>$longueur = round($longueur,0);</div><div>$longueur_metre=$longueur % 1000;</div><div>$longueur_km = ($longueur - $longueur_metre)/1000;</div><div>$msg= $longueur_km.'km'.$longueur_metre.'m';</div><div>
} else {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$msg= $longueur.'m';</div><div>}</div><div>return $msg;</div><div>}</div><div><br></div><div><br></div><div>function direction($x1,$y1,$x2,$y2,$x3,$y3,$x4,$y4,$typ)</div>
<div>{</div><div><br></div><div>$pi=pi();</div><div>$Gisement=100000;</div><div>$Gisement1=100000;</div><div>$dx=1000000*($x2-$x1);</div><div>$dy=1000000*($y2-$y1);</div><div><br></div><div>if (($dx==0)&&($dy==0)) </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$Gisement=0;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>if (($dy==0)&&($dx>0)) </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$Gisement=100;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>if (($dy==0)&&($dx<0)) </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>$Gisement=300;<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><br></div><div>if (($Gisement!=0)&&($Gisement!=100)&&($Gisement!=300))</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$di = atan(abs($dx/$dy))*200/$pi;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>if (($dx>=0)&&($dy<0)) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$di=200-$di;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (($dx<=0)&&($dy<0)) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$di=200+$di;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (($dx<=0)&&($dy>0)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$di=400-$di;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>$Gisement=$di;<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>
<br></div><div>$dx=1000000*($x3-$x4);</div><div>$dy=1000000*($y3-$y4);</div><div><br></div><div>if (($dx==0)&&($dy==0)) </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$Gisement1=0;<span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>if (($dy==0)&&($dx>0)) </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>$Gisement1=100;<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>if (($dy==0)&&($dx<0)) </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$Gisement1=300;<span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div>if (($Gisement1!=0)&&($Gisement1!=100)&&($Gisement1!=300))</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>$di = atan(abs($dx/$dy))*200/$pi;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (($dx>=0)&&($dy<0)) {</div><div>
<span class="Apple-tab-span" style="white-space:pre">                        </span>$di=200-$di;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (($dx<=0)&&($dy<0)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$di=200+$di;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (($dx<=0)&&($dy>0)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$di=400-$di;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$Gisement1=$di;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div>$g21=$Gisement;</div><div>$g23=$Gisement1;</div><div>$dir=-$g23+$g21+200;</div><div>if ($dir>200) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$dir = $dir-400;</div>
<div>}</div><div>if ($dir<-200) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$dir = $dir+400;</div><div>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if ($dir>=-10 AND $dir<=10) { </div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$msg="<IMG width=32 height=32 SRC=img/roadmap/21.gif> Continuer tout droit"; </div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>if ($dir>=-50 AND $dir<-10) { </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$msg="<IMG width=32 height=32 SRC=img/roadmap/22.gif> Serrer à droite"; </div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if ($dir>=-110 AND $dir<-50) { </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$msg="<IMG width=32 height=32 SRC=img/roadmap/22.gif> Tourner à droite"; </div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if ($dir>=-150 AND $dir<-100) { </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$msg="<IMG width=32 height=32 SRC=img/roadmap/22.gif>Tourner trop serrer à droite"; </div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if ($dir>=-200 AND $dir<-150) { </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$msg="<IMG width=32 height=32 SRC=img/roadmap/22.gif>Faite demi tour à droite"; </div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if ($dir>10 AND $dir<=50) { </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$msg="<IMG width=32 height=32 SRC=img/roadmap/24.gif>Serrer à gauche"; </div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if ($dir>50 AND $dir<=110) { </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$msg="<IMG width=32 height=32 SRC=img/roadmap/24.gif>Tourner à gauche"; </div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if ($dir>110 AND $dir<=150) { </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$msg="<IMG width=32 height=32 SRC=img/roadmap/24.gif>Tourner trop serrer à gauche"; </div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if ($dir>150 AND $dir<=200) { </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$msg="<IMG width=32 height=32 SRC=img/roadmap/24.gif>Faite demi tour à gauche"; </div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>if($typ==1)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div>$msg="<IMG width=32 height=32 SRC=img/roadmap/10.gif> Prendre le Rond Point : "; </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>RETURN $msg;</div><div>}</div><div><br></div><div><br></div><div><br></div>
<div> </div><div><br></div><div> </div><div> $counter = $pathlength = 0;</div><div><br></div><div> // Retrieve start point</div><div> $start = split(' ',$_REQUEST['startpoint']);</div><div> $startPoint1 = array($start[0], $start[1]);</div>
<div>$txtStart = $_REQUEST['txtstartpoint'];</div><div>$txtEnd = $_REQUEST['txtendpoint'];</div><div> //echo $_REQUEST['startpoint'];</div><div> </div><div> // Retrieve end point</div><div> $end = split(' ',$_REQUEST['finalpoint']);</div>
<div> $endPoint1 = array($end[0], $end[1]);</div><div>//echo $_REQUEST['finalpoint'];</div><div> // Find the nearest edge</div><div> $startEdge = findNearestEdge($startPoint1);</div><div> $endEdge = findNearestEdge($endPoint1);</div>
<div><br></div><div> // FUNCTION findNearestEdge</div><div> function findNearestEdge($lonlat) {</div><div> </div><div> // Connect to database</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> $con = pg_connect("host=".PG_HOST." </div>
<div> dbname=".PG_DB." </div><div> user=".PG_USER." </div><div> password=".PG_PASSWORD.""); </div><div> </div>
<div> //$con = pg_connect("dbname=".PG_DB." host=".PG_HOST." user=".PG_USER." password=".PG_PASSWORD);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div> $sql = "SELECT gid, source, target, the_geom, </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span> distance(the_geom, GeometryFromText(</div><div> 'POINT(".$lonlat[0]." ".$lonlat[1].")', -1)) AS dist </div>
<div> FROM ".TABLE." </div><div> WHERE the_geom && setsrid(</div><div> 'BOX3D(".($lonlat[0]-0.1)." </div><div> ".($lonlat[1]-0.1).", </div>
<div> ".($lonlat[0]+0.1)." </div><div> ".($lonlat[1]+0.1).")'::box3d, -1) </div><div> ORDER BY dist LIMIT 1";</div><div> //echo $sql; </div>
<div> $query = pg_query($con,$sql); </div><div> </div><div> $edge['gid'] = pg_fetch_result($query, 0, 0); </div><div> $edge['source'] = pg_fetch_result($query, 0, 1); </div><div> $edge['target'] = pg_fetch_result($query, 0, 2); </div>
<div> $edge['the_geom'] = pg_fetch_result($query, 0, 3); </div><div><br></div><div> // Close database connection</div><div> pg_close($con);</div><div><br></div><div> return $edge;</div><div> }</div><div>
<br></div><div> // Select the routing algorithm</div><div> switch($_REQUEST['method']) {</div><div><br></div><div> case 'SPD' : // Shortest Path Dijkstra </div><div><br></div><div> $sql = "SELECT rt.gid, AsText(rt.the_geom) AS wkt, </div>
<div> length(rt.the_geom) AS length, ".TABLE.".id </div><div> FROM ".TABLE.", </div><div> (SELECT gid, the_geom </div><div> FROM dijkstra_sp_delta(</div>
<div> '".TABLE."',</div><div> ".$startEdge['source'].",</div><div> ".$endEdge['target'].",</div>
<div> 0.01)</div><div> ) as rt </div><div> WHERE ".TABLE.".gid=rt.gid;";</div><div> break;</div><div><br></div><div> case 'SPA' : // Shortest Path A* </div>
<div><br></div><div> $sql = "SELECT rt.gid, AsText(rt.the_geom) AS wkt, </div><div> ".TABLE.".length, ".TABLE.".id, ".TABLE.".temps, ".TABLE.".on, ".TABLE.".typ, ".TABLE.".id , ".TABLE.".x1 as xs, ".TABLE.".y1 as ys, ".TABLE.".x2 as xe, ".TABLE.".y2 as ye </div>
<div> FROM ".TABLE.", </div><div> (SELECT * </div><div> FROM astar_sp_delta(</div><div> '".TABLE."',</div>
<div> ".$startEdge['source'].",</div><div> ".$endEdge['target'].",</div><div> 0.01)</div><div> ) as rt </div>
<div> WHERE ".TABLE.".gid=rt.gid;"; </div><div><br></div><div> break;</div><div><br></div><div> case 'SPS' : // Shortest Path Shooting*</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if ($_REQUEST['mode']==1) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>$sql = "SELECT rt.gid, AsText(rt.the_geom) AS wkt, </div><div> length(rt.the_geom) AS length, rt.length, rt.temps, rt.on, rt.typ, ".TABLE.".id , rt.xs, rt.ys, rt.xe, <a href="http://rt.ye">rt.ye</a></div>
<div> FROM ".TABLE.", </div><div> (SELECT a.gid, a.the_geom, b.temps, b.on, b.typ , b.length as length, b.x1 as xs, b.y1 as ys, b.x2 as xe, b.y2 as ye</div><div> FROM shootingstar_sp(</div>
<div> '".TABLE."',</div><div> ".$startEdge['gid'].",</div><div> ".$endEdge['gid'].",</div>
<div> 0.01, 'length',true, false) a, roads b where a.gid=b.gid</div><div> ) as rt </div><div> WHERE ".TABLE.".gid=rt.gid;"; </div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span> </div><div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span> } else {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$sql = "SELECT rt.gid, AsText(rt.the_geom) AS wkt, </div>
<div> length(rt.the_geom) AS length, rt.length, rt.temps, rt.on, rt.typ, ".TABLE.".id , rt.xs, rt.ys, rt.xe, <a href="http://rt.ye">rt.ye</a></div><div> FROM ".TABLE.", </div>
<div> (SELECT a.gid, a.the_geom, b.temps, b.on, b.typ , b.length as length, b.x1 as xs, b.y1 as ys, b.x2 as xe, b.y2 as ye</div><div> FROM shootingstar_sp(</div><div> '".TABLE."',</div>
<div> ".$startEdge['gid'].",</div><div> ".$endEdge['gid'].",</div><div> 0.01, 'temps',true, false) a, roads b where a.gid=b.gid</div>
<div> ) as rt </div><div> WHERE ".TABLE.".gid=rt.gid;"; </div><div><span class="Apple-tab-span" style="white-space:pre">        </span> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span> }</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> break;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> </div><div> } // close switch</div><div>//echo $sql;</div><div> // Database connection and query</div>
<div> $dbcon = pg_connect("host=".PG_HOST." </div><div> dbname=".PG_DB." </div><div> user=".PG_USER." </div><div> password=".PG_PASSWORD.""); </div>
<div> </div><div> $query = pg_query($dbcon,$sql); </div><div><span class="Apple-tab-span" style="white-space:pre">        </span> </div><div> // Return route as html table</div><div><br></div><div><br></div><div>$xml1 .= "<style type='text/css'>";</div>
<div>$xml1 .= "a:link {";</div><div>$xml1 .= "<span class="Apple-tab-span" style="white-space:pre">        </span>color: #FFCC00;";</div><div>$xml1 .= "}";</div><div>$xml1 .= "a:visited {";</div>
<div>$xml1 .= "<span class="Apple-tab-span" style="white-space:pre">        </span>color: #FFCC00;";</div><div>$xml1 .= "}";</div><div>$xml1 .= ".style1 {font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight: bold;}";</div>
<div>$xml1 .= ".style2 {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px;}"; </div><div>$xml1 .= ".style3 {color: #808080}";</div><div>$xml1 .= "</style>";</div><div>
echo $xml1;</div><div>//echo "depart ".$startEdge['gid']." -------<p>";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$xml .= "sql=".$sql." fin de la requête"; </div>
<div> $xml .= "<table width='100%' border='2' cellpadding='0' cellspacing='1' bordercolor='#FF9F00' bgcolor='#FFFFFF'>";</div><div> $xml .="<tr bordercolor='#C0C0C0'>";</div>
<div> $xml .= "<td><strong>Etape</strong></td>";</div><div> $xml .= "<td><strong>Id Tronçon</strong></td>";</div><div> </div><div> $xml .= "<td><strong>length Etape</strong></td>";</div>
<div> $xml .= "<td><strong>length Cumulé</strong></td>";</div><div> $xml .= "<td><strong>Temps moyen</strong></td>";</div><div> $xml .= "<td><strong>Nom de la Rue</strong></td>";</div>
<div> $xml .="</tr>"; </div><div> </div><div> // Add edges to XML file</div><div> while($edge=pg_fetch_assoc($query)) { </div><div><br></div><div> $pathlength += $edge['length'];</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>$xml .="<tr bordercolor='#C0C0C0'>";</div><div> $xml .= "<td> ".++$counter."</td>";</div><div> $xml .= "<td> ".$edge['gid']."</td>";</div>
<div>//déclaration des tableaux pour organisation de la feuille du route<span class="Apple-tab-span" style="white-space:pre">        </span></div><div>$ii[$counter] = $edge['gid'];<span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div>$startPoint[$counter] = array($edge['xs'], $edge['ys']);</div><div>$endPoint[$counter] = array($edge['xe'], $edge['ye']);</div><div>$rue[$counter] = $edge['on'];</div><div>$x1[$counter] = $edge['xs'];</div>
<div>$y1[$counter] = $edge['ys'];</div><div>$x2[$counter] = $edge['xe'];</div><div>$y2[$counter] = $edge['ye'];</div><div>$length[$counter]=$edge['length'];</div><div>$temps[$counter]=3600*40/(1000*$edge['length']);</div>
<div>$type[$counter]=$edge['typ'];</div><div><br></div><div>//fin des déclaration</div><div><br></div><div>$temps1=3600*40/(1000*$edge['length']);</div><div>$temps_trajet +=$temps1;</div><div>if ($temps1>60) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps1=$temps1/60;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps2=round($temps1,0)." mn";</div><div>}</div><div>
if ($temps1>3600) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps1=$temps1/3660;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps2=round($temps1,0)." h";</div>
<div>}</div><div>if ($temps1<60) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps1=$temps1;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$temps2=round($temps1,0)." s";</div>
<div>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$xml .= "<td> ".round($edge['length'],2)." m</td>";</div><div> $xml .= "<td> ".round(($pathlength),2)." m</td>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>$xml .= "<td> ".$edge['wkt']."</td>";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div>//pour vérifier le changement du rue par son nom </div><div>$on[$i+1]=$edge['on'];</div><div>$j = $i;</div><div>$i +=1;</div><div>if ($on[$i] != $on[$j]) </div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$xml .= "<td> <img src='img/roadmap/2.png'>".$edge['on'].".</td>";</div>
<div>}</div><div>else {</div><div>$xml .= "<td> ".$edge['on'].".</td>";<span class="Apple-tab-span" style="white-space:pre">        </span></div><div>}</div><div><br></div><div>$xml .="</tr>"; </div>
<div> }</div><div> $xml .= "</table>"; </div><div> // Close database connection</div><div> pg_close($dbcon);</div><div><br></div><div>echo "<h3 style='color:#2e585c;'>Feuille de route</h3>";</div>
<div><br></div><div> // Return routing result</div><div> //header('Content-type: text/xml',true);</div><div>echo "<div style='width:250px; float:left; border-left:1px solid #CCCCCC; border-right:1px solid #CCCCCC; padding:0 10px;'>";</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>echo "<span class='style3'>".htmlentities("Résumé du Trajet")."</span><br>";</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>if ($_REQUEST['method']=='SPA')</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>echo "<span class='style3'>".htmlentities("Mode de Navigation : ")."</span><span class='style3'>".htmlentities("Piéton")."</span></span><br>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if ($_REQUEST['method']=='SPS')</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>echo "<span class='style3'>Mode de Navigation :</span><span class='style3'>Voiture</span><br>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>if ($_REQUEST['mode']==1)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>echo "<span class='style3'>".htmlentities("Type d'itinéraire : ")."</span><span class='style3'>Le plus court</span><br>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>echo "<span class='style3'>".htmlentities("Type d'itinéraire : ")."</span><span class='style3'>Le plus Rapide</span><br>";<span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>echo "<span class='style3'>Longueur du Trajet : </span><span class='style3'>";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>echo ConvertDistance(round(($pathlength),0))."</span><br>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>echo "<span class='style3'>Temps total du Trajet : </span><span class='style3'>";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>echo ConvertTemps($temps_trajet)."</span></br>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>echo "</div>";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>echo "</br>";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>echo "</br>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>echo "</br>";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>echo "</br>";</div><div> //echo $xml;</div>
<div>// <span class="Apple-tab-span" style="white-space:pre">        </span> echo "<p>_______________________________________________<p>";</div><div>// echo $counter."<p>";</div><div>// echo "_______________________________________________<p>";</div>
<div>//for($i=1; $i<=$counter ; $i++) {</div><div>//echo "&&startPoint[".$i."] = array(".$x1[$i].",".$y1[$i].");<p>";</div><div>//echo "&&endPoint[".$i."] = array(".$x2[$i].",".$y2[$i].");<p>";</div>
<div>//echo "&&rue[".$i."] = |".$rue[$i]."|;<p>";</div><div>//}</div><div> </div><div> //recherche du premier tronçon de la route</div><div>for($i=1; $i<=$counter ; $i++) {</div>
<div> if ($ii[$i]==$startEdge['gid']) {</div><div>//<span class="Apple-tab-span" style="white-space:pre">        </span>echo "<script>alert(".$startEdge['gid'].");</script>"; </div>
<div> //stockage temporaire de la ligne n°1</div><div> $tt=$rue[1];</div><div> $st=$startPoint[1];</div><div> $se=$endPoint[1];</div><div> $ll= $length[1];</div><div> $tm= $temps[1];</div><div> $xxx1=$x1[1];</div><div>
$xxx2=$x2[1];</div><div> $yyy1=$y1[1];</div><div> $yyy2=$y2[1];</div><div> $type_route=$type[1];</div><div> //Attribution de la ligne n° 1 au premier tronçon de la route</div><div> $rue[1]=$rue[$i];</div><div> $startPoint[1]=$startPoint[$i];</div>
<div> $endPoint[1]=$endPoint[$i];</div><div> $length[1]=$length[$i];</div><div> $temps[1]=$temps[$i];</div><div> $x1[1]=$x1[$i];</div><div> $x2[1]=$x2[$i];</div><div> $y1[1]=$y1[$i];</div><div> $y2[1]=$y2[$i];</div>
<div> $type[1]=$type[$i];</div><div> //attribution du tronçon n° i de l'ex début de route par l'exe premier enregistrement</div><div> $rue[$i]=$tt;</div><div> $startPoint[$i]=$st;</div><div> $endPoint[$i]=$se;</div>
<div> $length[$i]=$ll;</div><div> $temps[$i]=$tm;</div><div> $x1[$i]=$xxx1;</div><div> $x2[$i]=$xxx2;</div><div> $y1[$i]=$yyy1;</div><div> $y2[$i]=$yyy2;</div><div> $type[$i]=$type_route;</div><div> } </div><div> }</div>
<div> </div><div> $i=1;</div><div> $j=1;</div><div> for($i=1; $i<=$counter ; $i++) </div><div> {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> for($j=$i+1; $j<=$counter ; $j++) </div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span> { </div><div><span class="Apple-tab-span" style="white-space:pre">                </span> if ($startPoint[$j]==$endPoint[$i]) </div><div><span class="Apple-tab-span" style="white-space:pre">                </span> {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T0=$startPoint[$j];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T1=$startPoint[$i+1];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T2=$endPoint[$j];</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T3=$endPoint[$i+1];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T4=$rue[$j];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T5=$rue[$i+1];</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T6=$length[$j];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T7=$length[$i+1];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T8=$temps[$j];</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T9=$temps[$i+1];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T10=$x1[$j];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T11=$x1[$i+1];</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T12=$y1[$j];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T13=$y1[$i+1];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T14=$x2[$j];</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T15=$x2[$i+1];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T16=$y2[$j];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T17=$y2[$i+1];</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T18=$type[$j];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$T19=$type[$i+1];</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span></div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$startPoint[$j]=$T1;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$startPoint[$i+1]=$T0;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$endPoint[$j]=$T3;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$endPoint[$i+1]=$T2;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$rue[$j]=$T5;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$rue[$i+1]=$T4;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$length[$j]=$T7;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$length[$i+1]=$T6;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$temps[$j]=$T9;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$temps[$i+1]=$T8;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$x1[$j]=$T11;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$x1[$i+1]=$T10;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$y1[$j]=$T13;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$y1[$i+1]=$T12;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$x2[$j]=$T15;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$x2[$i+1]=$T14;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$y2[$j]=$T17;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$y2[$i+1]=$T16;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>$type[$j]=$T19;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>$type[$i+1]=$T18;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span> }</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> }</div><div> }</div><div><br></div><div>//////////////////////////////////////////////////////////</div>
<div> /////////////////////////////////////////////////////////////</div><div> ////////////////////////////////////////////////////////</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span> for($i=0; $i<=$counter ; $i++) </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> //assemblage des tronçons par nom des rues</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>$comt_temp +=1;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>$temps_troncon += $temps[$i];</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>$temps_cumule +=$temps[$i];</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>$length_troncon +=$length[$i];</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>$length_cumule +=$length[$i];</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> if ($rue[$i+1]!=$rue[$i]) </div><div><span class="Apple-tab-span" style="white-space:pre">                </span> {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>$etape +=1;</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>if ($etape % 2 != 0) {<span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo "<tr bgcolor='#B8E1F5'>";</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo "<tr>";<span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo "<td><span class='style2'>".$etape."</span></td>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo "<td><span class='style1'>";</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>if ($i==1) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>//echo "<IMG width=32 height=32 SRC=img/drapeau/11.gif> Prendre ";</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>} elseif ($i==$counter) {</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>//echo "<IMG width=32 height=32 SRC=img/drapeau/12.gif> Arrivé à ";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                                                                                                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                                                </span>//echo direction($x1[$i-1],$y1[$i-1],$x1[$i],$y1[$i],$x1[$i+1],$y1[$i+1], $x1[$i+2],$y1[$i+2], $type[$i+1]);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                                </span>$direction[$i]=direction($x1[$i-1],$y1[$i-1],$x1[$i],$y1[$i],$x1[$i+1],$y1[$i+1], $x1[$i+2],$y1[$i+2], $type[$i+1]);</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo $rue[$i]."</span></td>";</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$NomRue[$i]=$rue[$i];</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo "<td><span class='style2'>";</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo ConvertDistance($length_troncon)."</span></td>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>$DistanceTroncon[$i]=ConvertDistance($length_troncon);</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo "<td><span class='style2'>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo ConvertDistance($length_cumule)."</span></td>";</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$DistanceCumul[$i]=ConvertDistance($length_cumule);<span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo "<td><span class='style2'>";</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo ConvertTemps($temps_troncon)."</span></td>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>$TempsTroncon[$i]=ConvertTemps($temps_troncon);</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo "<td><span class='style2'>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo ConvertTemps($temps_cumule)."</span></td>";</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$TempsCumul[$i]=ConvertTemps($temps_cumule);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>//echo "</tr>";</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>//initialiser le compteur</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>$comt_temp =0;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>$temps_troncon=0;</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>$length_troncon=0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> }</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> }</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> //echo "</table>";</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div>echo "<div style='background-color:#f0f0f0; color:#00519e; padding:0 10px; margin-bottom:5px;'><div style='float:left; width:275px;'><img src='img/drapeau/14.png'>".htmlentities("Départ")." : ".$txtStart."</div></div><br>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> echo "<div style='background-color:#f0f0f0; color:#00519e; padding:0 10px; margin-bottom:5px;'><div style='float:left; width:275px;'>".$direction[0]."</div>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> echo $DistanceTroncon[1]."</div>";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> echo "<div style='background-color:#f0f0f0; color:#00519e; padding:0 10px; margin-bottom:5px;'><div style='float:left; width:275px;'> de </div></div>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> echo "<div style='background-color:#f0f0f0; color:#00519e; padding:0 10px; margin-bottom:5px;'><div style='float:left; width:275px;'>".$NomRue[1]."</div></div>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> echo "<div style='background-color:#f0f0f0; color:#00519e; padding:0 10px; margin-bottom:5px;'><div style='float:left; width:275px;'>".htmlentities(" ")."</div></div>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> echo "<p>";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> for($i=1; $i<=$counter-2 ; $i++) </div><div><span class="Apple-tab-span" style="white-space:pre">        </span> {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>echo "<div style='background-color:#f0f0f0; color:#00519e; padding:0 10px; margin-bottom:5px;'><div style='float:left; width:275px;'>".$direction[$i]."</div></div>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>echo " ";</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>echo "<div style='background-color:#f0f0f0; color:#00519e; padding:0 10px; margin-bottom:5px;'><div style='float:left; width:275px;'>".$NomRue[$i+1]."</div>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>echo $DistanceTroncon[$i]."</div>";</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>//echo "coucou";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>//echo "<p>";</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>echo "<div style='background-color:#f0f0f0; color:#00519e; padding:0 10px; margin-bottom:5px;'><div style='float:left; width:275px;'>".$direction[$counter-1]."</div></div>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> echo "<div style='background-color:#f0f0f0; color:#00519e; padding:0 10px; margin-bottom:5px;'><div style='float:left; width:275px;'>".$direction[$i]."</div></div>";htmlentities(" et vous arrivez à ")."</div></div>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> echo "<div style='background-color:#f0f0f0; color:#00519e; padding:0 10px; margin-bottom:5px;'><div style='float:left; width:275px;'>".$NomRue[$counter]."</div>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> echo $DistanceTroncon[$counter-1]."</div></div>";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> echo "<div style='background-color:#f0f0f0; color:#00519e; padding:0 10px; margin-bottom:5px;'><div style='float:left; width:275px;'><img src='img/drapeau/15.png'>".htmlentities("Arrivé")." : ".$txtEnd."</div></div><br>";</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div>?></div><div>///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</div>
</div>