i'm working to find the shortest path in mapserver apllication after i created my layers which are 3 ( base layer , edge layer and node layer) i created my mapfile and the tree.js file ( javascript) and i created my php code everything runs good by the shortest path does not appear... i used pgr_aster algorithm to find the shortest path this part of my php code

 //get the starting point
            $start = split(' ',$_REQUEST['startpoint']);
            $startPoint = array($start[0], $start[1]);
// get the end point
            $end = split(' ',$_REQUEST['finalpoint']);
            $endPoint = array($end[0], $end[1]);

// Trouver le tronçon le plus proche
   $startEdge = findNearestEdge($startPoint);
   $endEdge = findNearestEdge($endPoint);

// FONCTION findNearestEdge
function findNearestEdge($lonlat) {
                               // Connexion à la base de données
                                  $con = pg_connect("host=localhost        port=5432 dbname=namebd user=postgres password=****");
                               // chercher le tronçon le plus proche   
                                  $sql = "SELECT id, source, target, the_geom, st_distance(the_geom, st_GeomFromText('POINT(".$lonlat[0]." ".$lonlat[1].")', 4326)) AS dist
                                          FROM projet
                                          WHERE (ST_dwithin(the_geom, st_GeomFromText('POINT(".$lonlat[0]." ".$lonlat[1].")', 4326),100))
                                          ORDER BY dist LIMIT 1";
                               // Lancer la requête de récupération 
                                   $query = pg_query($con,$sql);
                                   $edge['id'] = pg_fetch_result($query, 0, 0);
                                   $edge['source'] = pg_fetch_result($query, 0, 1);
                                   $edge['target'] = pg_fetch_result($query, 0, 2);
                                   $edge['the_geom'] = pg_fetch_result($query, 0, 3);

                               // Fermer la connexion
return $edge;

//définir l'algorithme de parcours

$sql = "SELECT id2 AS id, ST_AsGeoJSON(the_geom) AS geojson, pcc.costpcc AS      length
    FROM pgr_astar('select id,source,target,cost,x1,y1,x2,y2,reverse_cost
                    from projet',".$startEdge['source'].",".$endEdge['target'].",true,true)as di
    JOIN projet as pro
    ON pcc.id2=pro.id"; 

// Connexion with the database
$dbcon = pg_connect("host=localhost port=**** dbname=namebd user=postgres password=****");  

// run the query
$query = pg_query($dbcon,$sql); 


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.