<div dir="ltr"><div>Hi Emmanuel,</div><div><br></div><div>The workshop code you're posting is not the current one anymore and won't work anymore with pgRouting 2.0.</div><div><br></div><div>If you want to use the "old" PHP function, then you need to modify it:</div>

<div><br></div><div>* Write your own plpgsql wrapper function. You can take a look at the examples in the new workshop: <a href="http://workshop.pgrouting.org/chapters/wrapper.html">http://workshop.pgrouting.org/chapters/wrapper.html</a></div>

<div>* Change the function name, arguments, etc. according to your custom function in the PHP script.</div><div><br></div><div>Daniel</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jan 4, 2014 at 6:43 AM, Emmanuel Adegboye <span dir="ltr"><<a href="mailto:eaadegboye@googlemail.com" target="_blank">eaadegboye@googlemail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><div dir="ltr"><p style="clear:both;vertical-align:baseline;line-height:18px;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em;border:0px;padding:0px">



I'm having issues getting the pgrouting workshop to work on Postgresql 9.2/PostGIS 2.11 and pgrouting 2.0 on windows.</p><p style="clear:both;vertical-align:baseline;line-height:18px;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em;border:0px;padding:0px">



How can I rewrite the following php/sql code and make it compatible with my version:</p><pre style="max-height:600px;width:auto;background-color:rgb(238,238,238);margin-bottom:10px;padding:5px;vertical-align:baseline;line-height:18px;font-size:14px;overflow:auto;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;margin-top:0px;word-wrap:normal;border:0px">


<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><?</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">php

  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Database connection settings</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  define</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"PG_DB"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"routing"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  define</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"PG_HOST"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"localhost"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> 
  define</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"PG_USER"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"postgres"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  define</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"PG_PORT"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"5432"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> 
   define</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"PG_PASSWD"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">   </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"*******"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> 
  define</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"TABLE"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">   </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"eastlegon"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> 

  $counter </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> $pathlength </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Retrieve start point</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  $start </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> split</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">' '</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$_REQUEST</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'startpoint'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  $startPoint </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> array</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$start</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">],</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> $start</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">1</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Retrieve end point</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  $end </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> split</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">' '</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$_REQUEST</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'finalpoint'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  $endPoint </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> array</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$end</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">],</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> $end</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">1</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Find the nearest edge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  $startEdge </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> findNearestEdge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$startPoint</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  $endEdge   </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> findNearestEdge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$endPoint</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// FUNCTION findNearestEdge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">function</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> findNearestEdge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$lonlat</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Connect to database</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    $con </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> pg_connect</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"dbname="</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">PG_DB</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">" host="</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">PG_HOST</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">" user="</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">PG_USER</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">" password="</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">PG_PASSWD</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

    $sql </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"SELECT gid, source, target, the_geom, 
             distance(the_geom, GeometryFromText(
                  'POINT("</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$lonlat</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">].</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">" "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$lonlat</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">1</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">].</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">")', 4326)) AS dist 
            FROM "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"  
            WHERE the_geom && setsrid(
                  'BOX3D("</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$lonlat</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]-</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">200</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">).</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">" 
                         "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$lonlat</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">1</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]-</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">200</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">).</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">", 
                         "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$lonlat</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]+</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">200</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">).</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">" 
                         "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$lonlat</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">1</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]+</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">200</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">).</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">")'::box3d, 4326) 
            ORDER BY dist LIMIT 1"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

    $query </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> pg_query</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$con</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$sql</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">  

    $edge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'gid'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">      </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> pg_fetch_result</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$query</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">  
    $edge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'source'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">   </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> pg_fetch_result</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$query</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">1</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">  
    $edge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'target'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">   </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> pg_fetch_result</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$query</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">2</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">  
    $edge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'the_geom'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">]</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> pg_fetch_result</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$query</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">3</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">  

    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Close database connection</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    pg_close</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$con</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">return</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> $edge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Select the routing algorithm</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">switch</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$_REQUEST</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'method'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">])</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">case</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'SPD'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">:</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Shortest Path Dijkstra </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

      $sql </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"SELECT rt.gid, AsText(rt.the_geom) AS wkt, 
                   length(rt.the_geom) AS length, "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">".id 
                FROM "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">", 
                    (SELECT gid, the_geom 
                        FROM dijkstra_sp_delta(
                            '"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"',
                            "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$startEdge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'source'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">].</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">",
                            "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$endEdge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'target'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">].</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">",
                            3000)
                     ) as rt 
                WHERE "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">".gid=rt.gid;"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
      </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">break</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">case</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'SPA'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">:</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Shortest Path A* </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

      $sql </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"SELECT rt.gid, AsText(rt.the_geom) AS wkt, 
                     length(rt.the_geom) AS length, "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">".id 
                  FROM "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">", 
                      (SELECT gid, the_geom 
                          FROM astar_sp_delta(
                              '"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"',
                              "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$startEdge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'source'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">].</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">",
                              "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$endEdge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'target'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">].</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">",
                              3000)
                       ) as rt 
                  WHERE "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">".gid=rt.gid;"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">  
      </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">break</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">case</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'SPS'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">:</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Shortest Path Shooting*</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

      $sql </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"SELECT rt.gid, AsText(rt.the_geom) AS wkt, 
                     length(rt.the_geom) AS length, "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">".id 
                  FROM "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">", 
                      (SELECT gid, the_geom 
                          FROM shootingstar_sp(
                              '"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"',
                              "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$startEdge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'gid'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">].</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">",
                              "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$endEdge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">[</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'gid'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">].</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">",
                              3000, 'length', false, false)
                       ) as rt 
                  WHERE "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">TABLE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">".gid=rt.gid;"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
      </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">break</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">  

  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// close switch</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Database connection and query</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  $dbcon </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> pg_connect</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"dbname="</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">PG_DB</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">" host="</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">PG_HOST</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">" user="</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">PG_USER</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">" password="</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">PG_PASSWD</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

  $query </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> pg_query</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$dbcon</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">$sql</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> 

  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">// Return route as XML</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
  $xml  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">'<?xml version="1.0" encoding="UTF-8" standalone="yes" </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">?></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">'."\n";
  $xml .= "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"><route></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">\n";

  // Add edges to XML file
  while($edge=pg_fetch_assoc($query)) {  

    $pathlength += $edge['length'];

    $xml .= "\t</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"><edge</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(255,0,0)">id</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,255)">'".++$counter."'</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">\n";
    $xml .= "\t\t</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"><id></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">".$edge['id']."</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"></id></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">\n";
    $xml .= "\t\t</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"><wkt></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">".$edge['wkt']."</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"></wkt></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">\n";
    $xml .= "\t\t</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"><length></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">".round(($pathlength/1000),3)."</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"></length></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">\n";
    $xml .= "\t</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"></edge></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">\n";
  }

  $xml .= "</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"></route></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">\n";

  // Close database connection
  pg_close($dbcon);

  // Return routing result
  header('Content-type: text/xml',true);
  echo $xml;

</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">?></span></code></pre><p style="clear:both;vertical-align:baseline;line-height:18px;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em;border:0px;padding:0px">



Thanks,</p></div>
</div></div><br>_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse">Georepublic UG & Georepublic Japan<br>

eMail: <a href="mailto:daniel.kastl@georepublic.de" style="color:rgb(66,99,171)" target="_blank">daniel.kastl@georepublic.de</a><br>Web: <a href="http://georepublic.de/" style="color:rgb(66,99,171)" target="_blank">http://georepublic.de</a></span>
</div>