I want any readymade code on pgrouting using php with background layer from geoserver, openlayer. Anyone can heilp please? thanks in advance

Vishal Source

I am a student doing project in pgrouting using PHP, I have gone through many pgrouting solutionns from FOSS4G to individuals. But I fail to get it working on my sysetm. Thus I request if any of you have already made/redimade code by which i can easily make it run on my system, please send me please... I am in great trouble , its matter of my career . Please help me I will be very much thankful to you.

I am using postgresql,php to display shortest distance, anyone plz give me codes. Here's my code - i m unable to display the query running.

<html>
  <head>
    <link rel="stylesheet" href="style.css" type="text/css">
    <script src="OpenLayers.js"></script>
    <script src="rout.js"></script>
    </head>
    <body onload="init()">
   <div id="map" class="container" align="left")>
        <?php
     // Database connection settings
     define("PG_DB"  , "haryana");
     define("PG_HOST", "localhost"); 
     define("PG_USER", "postgres");
     define("PG_PORT", "5432"); 
     define("TABLE",  "highways");  $dbcon = pg_connect("host=localhost port=5432 dbname=haryana user=postgres 
     password=nrsc");
     $sql = "SELECT route.id2, ST_AsGeoJSON(highways.geom) AS geojson, 
         ST_length(highways.geom) AS length,highways.gid
            FROM pgr_dijkstra('SELECT gid AS id,
                source::integer,
                target::integer,
                length::double precision AS cost
                FROM highways',1,600, false, false ) 
            AS route LEFT JOIN highways ON route.id2 = highways.gid";
       $query = pg_query($dbcon,$sql); 
       echo $query;
       // Return route as GeoJSON
        $geojson = array(
       'type'      => 'FeatureCollection',
       'features'  => array()
        ); 

     // Add edges to GeoJSON array
     while($edge=pg_fetch_assoc($query)) {  
     $feature = array(
      'type' => 'Feature',
      'geometry' => json_decode($edge['geojson'], true),
      'crs' => array(
        'type' => 'EPSG',
        'properties' => array('code' => '4326')
      ),
     'properties' => array(
        'id' => $edge['id'],
         'length' => $edge['length']
      )
    );

  // Add feature array to feature collection array
  array_push($geojson['features'], $feature);
   }

// Close database connection
 pg_close($dbcon);
 // Return routing result
 //header('Content-type: application/json',true);
 //echo json_encode($geojson);
 ?>
</div>

phpopenlayerspostgresql-9.4

Answers

comments powered by Disqus