Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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>
Add Comment
Please, Sign In to add comment