Guest User

Untitled

a guest
Feb 15th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <html>
  2. <head>
  3. <link rel="stylesheet" href="style.css" type="text/css">
  4. <script src="OpenLayers.js"></script>
  5. <script src="rout.js"></script>
  6. </head>
  7. <body onload="init()">
  8. <div id="map" class="container" align="left")>
  9. <?php
  10. // Database connection settings
  11. define("PG_DB" , "haryana");
  12. define("PG_HOST", "localhost");
  13. define("PG_USER", "postgres");
  14. define("PG_PORT", "5432");
  15. define("TABLE", "highways"); $dbcon = pg_connect("host=localhost port=5432 dbname=haryana user=postgres
  16. password=nrsc");
  17. $sql = "SELECT route.id2, ST_AsGeoJSON(highways.geom) AS geojson,
  18. ST_length(highways.geom) AS length,highways.gid
  19. FROM pgr_dijkstra('SELECT gid AS id,
  20. source::integer,
  21. target::integer,
  22. length::double precision AS cost
  23. FROM highways',1,600, false, false )
  24. AS route LEFT JOIN highways ON route.id2 = highways.gid";
  25. $query = pg_query($dbcon,$sql);
  26. echo $query;
  27. // Return route as GeoJSON
  28. $geojson = array(
  29. 'type' => 'FeatureCollection',
  30. 'features' => array()
  31. );
  32.  
  33. // Add edges to GeoJSON array
  34. while($edge=pg_fetch_assoc($query)) {
  35. $feature = array(
  36. 'type' => 'Feature',
  37. 'geometry' => json_decode($edge['geojson'], true),
  38. 'crs' => array(
  39. 'type' => 'EPSG',
  40. 'properties' => array('code' => '4326')
  41. ),
  42. 'properties' => array(
  43. 'id' => $edge['id'],
  44. 'length' => $edge['length']
  45. )
  46. );
  47.  
  48. // Add feature array to feature collection array
  49. array_push($geojson['features'], $feature);
  50. }
  51.  
  52. // Close database connection
  53. pg_close($dbcon);
  54. // Return routing result
  55. //header('Content-type: application/json',true);
  56. //echo json_encode($geojson);
  57. ?>
  58. </div>
Add Comment
Please, Sign In to add comment