<div dir="ltr"><p>Regina.</p>
<p>It was from the foss4g 2007 workshop. The most recent worshops include wrapper functions which I am not familiar with so I also get stuck at some point.</p>
<p>What I am trying to do is to create a simple application that allows users to set a start and end point and calculate the route using any one of the major algorithms like the workshop describes.</p>
<p>So far, the user interface (based on openlayers 2.10) works well and displays both points. I get an error in firebug when I click the 'calculate route' button and the php script is called, and this was after I installed legacy.sql. I get "ERROR: type "geoms" does not exist" when installing pgrouting.sql.</p>
<p>Here's the error from firebug:<br><br></p><pre><code class=""><br />
</code><code class=""><b>Warning</b>: pg_query(): Query failed: ERROR: parse error - invalid geometry
</code><code class="">HINT: "POINT( )" <-- parse error at position 9 within geometry in <b>C:\ms4w\Apache\htdocs</code><code class="">\hgt\routing.php</b> on line <b>42</b><br />
</code><code class=""><br />
</code><code class=""><b>Warning</b>: pg_fetch_result() expects parameter 1 to be resource, boolean given in <b>C:\ms4w\Apache</code><code class="">\htdocs\hgt\routing.php</b> on line <b>44</b><br />
</code><code class=""><br />
</code><code class=""><b>Warning</b>: pg_fetch_result() expects parameter 1 to be resource, boolean given in <b>C:\ms4w\Apache</code><code class="">\htdocs\hgt\routing.php</b> on line <b>45</b><br />
</code><code class=""><br />
</code><code class=""><b>Warning</b>: pg_fetch_result() expects parameter 1 to be resource, boolean given in <b>C:\ms4w\Apache</code><code class="">\htdocs\hgt\routing.php</b> on line <b>46</b><br />
</code><code class=""><br />
</code><code class=""><b>Warning</b>: pg_fetch_result() expects parameter 1 to be resource, boolean given in <b>C:\ms4w\Apache</code><code class="">\htdocs\hgt\routing.php</b> on line <b>47</b><br />
</code><code class=""><br />
</code><code class=""><b>Warning</b>: pg_query(): Query failed: ERROR: parse error - invalid geometry
</code><code class="">HINT: "POINT( )" <-- parse error at position 9 within geometry in <b>C:\ms4w\Apache\htdocs</code><code class="">\hgt\routing.php</b> on line <b>42</b><br />
</code><code class=""><br />
</code><code class=""><b>Warning</b>: pg_fetch_result() expects parameter 1 to be resource, boolean given in <b>C:\ms4w\Apache</code><code class="">\htdocs\hgt\routing.php</b> on line <b>44</b><br />
</code><code class=""><br />
</code><code class=""><b>Warning</b>: pg_fetch_result() expects parameter 1 to be resource, boolean given in <b>C:\ms4w\Apache</code><code class="">\htdocs\hgt\routing.php</b> on line <b>45</b><br />
</code><code class=""><br />
</code><code class=""><b>Warning</b>: pg_fetch_result() expects parameter 1 to be resource, boolean given in <b>C:\ms4w\Apache</code><code class="">\htdocs\hgt\routing.php</b> on line <b>46</b><br />
</code><code class=""><br />
</code><code class=""><b>Warning</b>: pg_fetch_result() expects parameter 1 to be resource, boolean given in <b>C:\ms4w\Apache</code><code class="">\htdocs\hgt\routing.php</b> on line <b>47</b><br />
</code><code class=""><br />
</code><code class=""><b>Warning</b>: pg_query(): Query failed: in <b>C:\ms4w\Apache\htdocs\hgt\routing.php</b> on line </code><code class=""><b>108</b><br />
</code><code class=""><br />
</code><code class=""><b>Warning</b>: pg_fetch_assoc() expects parameter 1 to be resource, boolean given in <b>C:\ms4w\Apache</code><code class="">\htdocs\hgt\routing.php</b> on line <b>115</b><br />
</code><code class=""><?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
</code><code class=""><route>
</code><code class=""></route></code></pre>
<p><br></p><p><br></p><p>And the html document:<br></p><p><br></p><p><!DOCTYPE html></p><p><html></p><p><head></p><p><title>pgRouting Demo</title></p><p><link rel="stylesheet" href="openlayers/theme/default/style.css" type="text/css"></p>
<p><style></p><p>#map-id {</p><p>width: 100%;</p><p>height: 512px;</p><p>border: 1px solid black;</p><p>}</p><p></style></p><p><script src="openlayers/OpenLayers.js"></script></p><p></head></p>
<p><body></p><p><div id="map-id"></div></p><p><script></p><p>var SinglePoint = OpenLayers.Class.create();</p><p>SinglePoint.prototype = OpenLayers.Class.inherit(OpenLayers.Handler.Point, {</p>
<p>createFeature: function(evt) {</p><p>this.control.layer.removeFeatures(this.control.layer.features);</p><p>OpenLayers.Handler.Point.prototype.createFeature.apply(this, arguments);</p><p>}</p><p>});</p><p>var start_style = OpenLayers.Util.applyDefaults({</p>
<p>externalGraphic: "start.png",</p><p>graphicWidth: 18,</p><p>graphicHeight: 26,</p><p>graphicYOffset: -26,</p><p>graphicOpacity: 1</p><p>}, OpenLayers.Feature.Vector.style['default']);</p><p>var stop_style = OpenLayers.Util.applyDefaults({</p>
<p>externalGraphic: "stop.png",</p><p>graphicWidth: 18,</p><p>graphicHeight: 26,</p><p>graphicYOffset: -26,</p><p>graphicOpacity: 1</p><p>}, OpenLayers.Feature.Vector.style['default']);</p><p>var result_style = OpenLayers.Util.applyDefaults({</p>
<p>strokeWidth: 3,</p><p>strokeColor: "#ff0000",</p><p>fillOpacity: 0</p><p>}, OpenLayers.Feature.Vector.style['default']);</p><p>// global variables</p><p>var map, parser, start, stop, result, controls;</p>
<p>var format = 'image/png';</p><p>var bounds = new OpenLayers.Bounds(</p><p> -0.178166372987693, 5.62323476776518,</p><p> -0.140817506885068, 5.64840001174401</p><p> );</p>
<p>var options = {</p><p> controls: [],</p><p> maxExtent: bounds,</p><p> maxResolution: 0.0001458940082134,</p><p> projection: "EPSG:4326",</p>
<p> units: 'degrees'</p><p><span class="" style="white-space:pre"> </span>};</p><p>map = new OpenLayers.Map("map-id", options);</p><p>boundary = new OpenLayers.Layer.WMS(</p><p> "East Legon - Boundary", "<a href="http://localhost:8080/geoserver/pgrouting/wms">http://localhost:8080/geoserver/pgrouting/wms</a>",</p>
<p> {</p><p> LAYERS: 'pgrouting:eastlegonboundary',</p><p> STYLES: '',</p><p> format: format,</p><p> tiled: true,</p>
<p> tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom</p><p> },</p><p> {</p><p> buffer: 0,</p><p> displayOutsideMaxExtent: true,</p>
<p> isBaseLayer: true,</p><p> yx : {'EPSG:4326' : true}</p><p> } </p><p> );</p><p>eastlegon = new OpenLayers.Layer.WMS(</p><p> "East Legon", "<a href="http://localhost:8080/geoserver/pgrouting/wms">http://localhost:8080/geoserver/pgrouting/wms</a>",</p>
<p> {</p><p> LAYERS: 'pgrouting:eastlegon',</p><p> STYLES: '',</p><p> format: format,</p><p><span class="" style="white-space:pre"> </span>transparent: true,</p>
<p> tiled: true,</p><p> tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom</p><p> },</p><p> {</p><p> buffer: 0,</p>
<p> displayOutsideMaxExtent: true,</p><p> isBaseLayer: false,</p><p> yx : {'EPSG:4326' : true}</p><p> } </p><p> );</p>
<p>start = new OpenLayers.Layer.Vector("Start Point", {style: start_style});</p><p>stop = new OpenLayers.Layer.Vector("End Point", {style: stop_style});</p><p>result = new OpenLayers.Layer.Vector("Routing Results",</p>
<p>{style: result_style});</p><p>map.addLayers([boundary, eastlegon, start, stop, result]);</p><p>map.addControl(new OpenLayers.Control.LayerSwitcher());</p><p>map.addControl(new OpenLayers.Control.PanPanel());</p><p>map.addControl(new OpenLayers.Control.ZoomPanel());</p>
<p>map.addControl(new OpenLayers.Control.ScaleLine());</p><p>map.addControl(new OpenLayers.Control.Navigation());</p><p>map.addControl(new OpenLayers.Control.MousePosition());</p><p>map.zoomToExtent(bounds);</p><p>// controls</p>
<p>controls = {</p><p>start: new OpenLayers.Control.DrawFeature(start, SinglePoint),</p><p>stop: new OpenLayers.Control.DrawFeature(stop, SinglePoint)</p><p>}</p><p>for (var key in controls) {</p><p>map.addControl(controls[key]);</p>
<p>}</p><p>function toggleControl(element) {</p><p>for (key in controls) {</p><p>if (element.value == key && element.checked) {</p><p>controls[key].activate();</p><p>} else {</p><p>controls[key].deactivate();</p>
<p>
}</p><p>}</p><p>}</p><p>function compute() {</p><p> var startPoint = start.features[0];</p><p> var stopPoint = stop.features[0];</p><p><br></p><p> if (startPoint && stopPoint) {</p>
<p> var result = {</p><p> startpoint: startPoint.geometry.x + ' ' + startPoint.geometry.y,</p><p> finalpoint: stopPoint.geometry.x + ' ' + stopPoint.geometry.y,</p>
<p> method: OpenLayers.Util.getElement('method').value,</p><p> region: "eastlegon",</p><p> srid: "4326"</p><p> };</p><p>
OpenLayers.loadURL("./routing.php",</p>
<p> OpenLayers.Util.getParameterString(result),</p><p> null,</p><p> displayRoute);</p><p> }</p><p> }</p>
<p><br></p><p> function displayRoute(response) {</p><p> if (response && response.responseXML) {</p><p> // erase the previous results</p><p> result.removeFeatures(result.features);</p>
<p><br></p><p> // parse the features</p><p> var edges = response.responseXML.getElementsByTagName('edge');</p><p> var features = [];</p><p> for (var i = 0; i < edges.length; i++) {</p>
<p> var g = parser.read(edges[i].getElementsByTagName('wkt')[0].textContent);</p><p> features.push(new OpenLayers.Feature.Vector(g));</p><p> }</p><p> result.addFeatures(features);</p>
<p> }</p><p> }</p><p></script></p><p><ul></p><p><li></p><p><input type="radio" name="control" id="noneToggle"</p><p>onclick="toggleControl(this);" checked="checked" /></p>
<p><label for="noneToggle">navigate</label></p><p></li></p><p><li></p><p><input type="radio" name="control" value="start" id="startToggle"</p><p>
onclick="toggleControl(this);" /></p><p><label for="startToggle">set start point</label></p><p></li></p><p><li></p><p><input type="radio" name="control" value="stop" id="stopToggle"</p>
<p>onclick="toggleControl(this);" /></p><p><label for="stopToggle">set stop point</label></p><p></li></p><p></ul></p><p><select id="method"></p><p><option value="SPD">Shortest Path Dijkstra - undirected (BBox)</option></p>
<p><option value="SPA">Shortest Path A Star - undirected</option></p><p><option value="SPS">Shortest Path Shooting Star</option></p><p></select></p><p><button onclick="compute()">Calculate Route</button></p>
<p></body></p><p></html></p><p><br></p><p><br></p>
<div class="gmail_quote">On Jan 4, 2014 3:45 AM, "Paragon Corporation" <<a href="mailto:lr@pcorp.us" target="_blank">lr@pcorp.us</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<u></u>
<div>
<div dir="ltr" align="left"><span><font face="Tahoma">Emmanuel,</font></span></div>
<div dir="ltr" align="left"><span><font face="Tahoma"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Tahoma">That PHP code looks like it was written for pgRouting 1.0.
Which workshop did you get that from? </font></span></div>
<div dir="ltr" align="left"><span><font face="Tahoma"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Tahoma">Most of the pgRouting 2.0 functions are prefixed with pgr_. There
should be a file in your install called</font></span></div>
<div dir="ltr" align="left"><span><font face="Tahoma"> In C:/Program
Files/PostgreSQL/9.2/share/extensions/pgrouting_legacy.sql which installs the
1.0 function names. You could try using that though I haven't personally
had a need to.</font></span></div>
<div dir="ltr" align="left"><span><font face="Tahoma"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Tahoma">One other thing I did notice about this code which I think
is a bug is that although PG_PORT is defined, it doesn't seem to be used for
pg_connect, so will not work without modification if you are runnning postgres
on non-default port (5432).</font></span></div>
<div dir="ltr" align="left"><span><font face="Tahoma"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Tahoma">Hope that helps,</font></span></div>
<div dir="ltr" align="left"><span><font face="Tahoma">Regina</font></span></div>
<div dir="ltr" align="left"><span><font face="Tahoma"><a href="http://www.postgis.us" target="_blank">http://www.postgis.us</a></font></span></div>
<div dir="ltr" align="left"><span><font face="Tahoma"><a href="http://www.bostongis.com" target="_blank">http://www.bostongis.com</a></font></span></div>
<div dir="ltr" align="left"><span><font face="Tahoma"><a href="http://www.paragoncorporation.com" target="_blank">http://www.paragoncorporation.com</a></font></span></div>
<div dir="ltr" align="left"><span><font face="Tahoma"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Tahoma"></font></span> </div><font face="Tahoma"></font><br>
<div lang="en-us" dir="ltr" align="left">
<hr>
<font face="Tahoma"><b>From:</b> <a href="mailto:pgrouting-users-bounces@lists.osgeo.org" target="_blank">pgrouting-users-bounces@lists.osgeo.org</a>
[mailto:<a href="mailto:pgrouting-users-bounces@lists.osgeo.org" target="_blank">pgrouting-users-bounces@lists.osgeo.org</a>] <b>On Behalf Of </b>Emmanuel
Adegboye<br><b>Sent:</b> Friday, January 03, 2014 4:42 PM<br><b>To:</b>
<a href="mailto:pgrouting-users@lists.osgeo.org" target="_blank">pgrouting-users@lists.osgeo.org</a><br><b>Subject:</b> [pgrouting-users] Issues with
pgrouting workshop code in postgis2.11/pgrouting 2.0<br></font><br></div>
<div></div>
<div dir="ltr">
<p style="padding:0px;border:0px;vertical-align:baseline;clear:both;line-height:18px;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em">
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="padding:0px;border:0px;vertical-align:baseline;clear:both;line-height:18px;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em">
How
can I rewrite the following php/sql code and make it compatible with my
version:</p><pre style="padding:5px;border:0px;max-height:600px;width:auto;background-color:rgb(238,238,238);margin-bottom:10px;vertical-align:baseline;line-height:18px;overflow:auto;font-size:14px;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">
<code style="border:0px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;vertical-align:baseline;padding:0px;margin:0px"><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"><?</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">php
</span><span style="border:0px;vertical-align:baseline;color:gray;padding:0px;margin:0px;background-color:transparent">// Database connection settings</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
define</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"PG_DB"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"routing"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
define</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"PG_HOST"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"localhost"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
define</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"PG_USER"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"postgres"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
define</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"PG_PORT"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"5432"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
define</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"PG_PASSWD"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"*******"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
define</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"TABLE"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"eastlegon"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$counter </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> $pathlength </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">0</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">;</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:gray;padding:0px;margin:0px;background-color:transparent">// Retrieve start point</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$start </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> split</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">' '</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$_REQUEST</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'startpoint'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$startPoint </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> array</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$start</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">0</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">],</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> $start</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">1</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:gray;padding:0px;margin:0px;background-color:transparent">// Retrieve end point</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$end </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> split</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">' '</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$_REQUEST</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'finalpoint'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$endPoint </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> array</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$end</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">0</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">],</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> $end</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">1</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:gray;padding:0px;margin:0px;background-color:transparent">// Find the nearest edge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$startEdge </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> findNearestEdge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$startPoint</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$endEdge </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> findNearestEdge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$endPoint</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:gray;padding:0px;margin:0px;background-color:transparent">// FUNCTION findNearestEdge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:rgb(0,0,139);padding:0px;margin:0px;background-color:transparent">function</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> findNearestEdge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$lonlat</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">)</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">{</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:gray;padding:0px;margin:0px;background-color:transparent">// Connect to database</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$con </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> pg_connect</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"dbname="</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">PG_DB</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">" host="</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">PG_HOST</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">" user="</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">PG_USER</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">" password="</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">PG_PASSWD</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$sql </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"SELECT gid, source, target, the_geom,
distance(the_geom, GeometryFromText(
'POINT("</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$lonlat</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">0</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">].</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">" "</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$lonlat</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">1</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">].</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">")', 4326)) AS dist
FROM "</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">TABLE</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"
WHERE the_geom && setsrid(
'BOX3D("</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$lonlat</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">0</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]-</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">200</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">).</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"
"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$lonlat</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">1</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]-</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">200</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">).</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">",
"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$lonlat</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">0</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]+</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">200</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">).</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"
"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$lonlat</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">1</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]+</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">200</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">).</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">")'::box3d, 4326)
ORDER BY dist LIMIT 1"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">;</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$query </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> pg_query</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$con</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$sql</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$edge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'gid'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> pg_fetch_result</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$query</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">0</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">0</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$edge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'source'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> pg_fetch_result</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$query</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">0</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">1</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$edge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'target'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> pg_fetch_result</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$query</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">0</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">2</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$edge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'the_geom'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">]</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> pg_fetch_result</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$query</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">0</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">,</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">3</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:gray;padding:0px;margin:0px;background-color:transparent">// Close database connection</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
pg_close</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$con</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">);</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:rgb(0,0,139);padding:0px;margin:0px;background-color:transparent">return</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> $edge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">;</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">}</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:gray;padding:0px;margin:0px;background-color:transparent">// Select the routing algorithm</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:rgb(0,0,139);padding:0px;margin:0px;background-color:transparent">switch</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">(</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$_REQUEST</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'method'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">])</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">{</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:rgb(0,0,139);padding:0px;margin:0px;background-color:transparent">case</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'SPD'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">:</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:gray;padding:0px;margin:0px;background-color:transparent">// Shortest Path Dijkstra </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$sql </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"SELECT rt.gid, AsText(rt.the_geom) AS wkt,
length(rt.the_geom) AS length, "</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">TABLE</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">".id
FROM "</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">TABLE</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">",
(SELECT gid, the_geom
FROM dijkstra_sp_delta(
'"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">TABLE</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"',
"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$startEdge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'source'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">].</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">",
"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$endEdge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'target'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">].</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">",
3000)
) as rt
WHERE "</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">TABLE</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">".gid=rt.gid;"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">;</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:rgb(0,0,139);padding:0px;margin:0px;background-color:transparent">break</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">;</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:rgb(0,0,139);padding:0px;margin:0px;background-color:transparent">case</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'SPA'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">:</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:gray;padding:0px;margin:0px;background-color:transparent">// Shortest Path A* </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
$sql </span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">=</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent"> </span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"SELECT rt.gid, AsText(rt.the_geom) AS wkt,
length(rt.the_geom) AS length, "</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">TABLE</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">".id
FROM "</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">TABLE</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">",
(SELECT gid, the_geom
FROM astar_sp_delta(
'"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">TABLE</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">"',
"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$startEdge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'source'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">].</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">",
"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">$endEdge</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">[</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">'target'</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">].</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">",
3000)
) as rt
WHERE "</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">TABLE</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">.</span><span style="border:0px;vertical-align:baseline;color:rgb(128,0,0);padding:0px;margin:0px;background-color:transparent">".gid=rt.gid;"</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">;</span><span style="border:0px;vertical-align:baseline;padding:0px;margin:0px;background-color:transparent">
</span><span style="border:0px;vertical-align:baseline;color:rgb(0,0,139);padding:0px;margin:0px;background-color:transparent"></span></code></pre>
</div></div><br>_______________________________________________<br>
Pgrouting-users mailing list<br>
<a href="mailto:Pgrouting-users@lists.osgeo.org" target="_blank">Pgrouting-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/pgrouting-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/pgrouting-users</a><br>...</blockquote></div>
</div>