[ka-Map-users] kaRouting, start and end definition

Daniel Muller Daniel.Muller at geomatic.ch
Mon Jan 29 08:04:33 EST 2007


Hi all,

The actual code for the definition of Etart and End point in 
kaRouting.php looks for the nearest edge Start and the nearest edge End 
point.

This was giving me strange results, not taking an edge near my point.

I've made some changes to the kaRouting.php file to find the nearest 
edge and on this edge to take the nearest extremity.

By doing that, I am no more using the "myNodesTable" and use only the 
data in the "myGraphTable".

I've put my modifications in the attached patch file for those who are 
interested.


Daniel
-------------- next part --------------
--- kaRouting.php	2007-01-29 12:28:28.000000000 +0100
+++ kaRouting.php	2007-01-29 12:30:54.000000000 +0100
@@ -85,10 +85,8 @@
   }
   $delta=$kaRoute['buffer'] ;
   /* getting start and end points id*/
-  $sql="SELECT source FROM $kaRoute[myGraphTable] as mytable ,(SELECT  gid , distance(snode, geometryfromtext(
-      'POINT(".$aStart[0]." ".$aStart[1].")', -1)) AS dist FROM $kaRoute[myNodesTable] 
-      WHERE snode && expand(geometryfromtext(
-      'POINT(".$aStart[0]." ".$aStart[1].")', -1),".$delta.") ORDER BY dist LIMIT 1) as foo WHERE mytable.gid=foo.gid;"; 
+  /* select the nearest extremity of the nearest segement */
+  $sql="select source,distance(startPoint(the_geom),geometryfromtext( 'POINT(".$aStart[0]." ".$aStart[1].")', -1)) AS dist2 FROM $kaRoute[myGraphTable] , (SELECT gid , distance(the_geom, geometryfromtext( 'POINT(".$aStart[0] ." ".$aStart[1].")', -1)) AS dist FROM $kaRoute[myGraphTable] WHERE the_geom && expand(geometryfromtext( 'POINT(".$aStart[0] ." ".$aStart[1].")', -1),".$delta.") ORDER BY dist LIMIT 1) as foo WHERE $kaRoute[myGraphTable].gid=foo.gid union select target,distance(endPoint(the_geom),geometryfromtext( 'POINT(".$aStart[0] ." ".$aStart[1].")', -1)) AS dist2 FROM $kaRoute[myGraphTable] , (SELECT gid , distance(the_geom, geometryfromtext( 'POINT(".$aStart[0] ." ".$aStart[1].")', -1)) AS dist FROM $kaRoute[myGraphTable] WHERE the_geom && expand(geometryfromtext( 'POINT(".$aStart[0] ." ".$aStart[1].")', -1),".$delta.") ORDER BY dist LIMIT 1) as foo WHERE $kaRoute[myGraphTable].gid=foo.gid order by dist2 limit 1;";
 //echo("<br> $sql");  
     if(isset($_REQUEST['debug'])) $dbcon = pg_connect( $conStr );
     else @$dbcon = pg_connect( $conStr );
@@ -109,10 +107,7 @@
       }
     }
   }
-  $sql="SELECT target FROM $kaRoute[myGraphTable]  as mytable , (SELECT gid , distance(enode, geometryfromtext(
-      'POINT(".$aEnd[0]." ".$aEnd[1].")', -1)) AS dist FROM $kaRoute[myNodesTable] 
-      WHERE enode && expand(geometryfromtext(
-      'POINT(".$aEnd[0]." ".$aEnd[1].")', -1),".$delta.") ORDER BY dist  LIMIT 1) as foo WHERE mytable.gid=foo.gid;"; 
+  $sql="select source,distance(startPoint(the_geom),geometryfromtext( 'POINT(".$aEnd[0]." ".$aEnd[1].")', -1)) AS dist2 FROM $kaRoute[myGraphTable] , (SELECT gid , distance(the_geom, geometryfromtext( 'POINT(".$aEnd[0] ." ".$aEnd[1].")', -1)) AS dist FROM $kaRoute[myGraphTable] WHERE the_geom && expand(geometryfromtext( 'POINT(".$aEnd[0] ." ".$aEnd[1].")', -1),".$delta.") ORDER BY dist LIMIT 1) as foo WHERE $kaRoute[myGraphTable].gid=foo.gid union select target,distance(endPoint(the_geom),geometryfromtext( 'POINT(".$aEnd[0] ." ".$aEnd[1].")', -1)) AS dist2 FROM $kaRoute[myGraphTable] , (SELECT gid , distance(the_geom, geometryfromtext( 'POINT(".$aEnd[0] ." ".$aEnd[1].")', -1)) AS dist FROM $kaRoute[myGraphTable] WHERE the_geom && expand(geometryfromtext( 'POINT(".$aEnd[0] ." ".$aEnd[1].")', -1),".$delta.") ORDER BY dist LIMIT 1) as foo WHERE $kaRoute[myGraphTable].gid=foo.gid order by dist2 limit 1;";
 //echo("<br> $sql"); 
  if( $dbcon )
   {


More information about the ka-Map-users mailing list