Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Connecting, selecting database
- $dbconn = pg_connect("host=localhost port=5432 dbname=routing user=postgres password=p8dx2780")
- or die('Could not connect: ' . pg_last_error());
- // Performing SQL query
- //$query = 'SELECT st_asgeojson(st_union(the_geom)) FROM export';
- //$result = pg_query($query) or die('Query failed: ' . pg_last_error());
- $x = $_GET["x"];
- $y = $_GET["y"];
- $sql = 'SELECT ST_AsGeoJSON(v.the_geom)
- FROM (SELECT ST_SetSRID(ST_Point('$y','$x'),
- 900913) As the_geom) As b LEFT JOIN vertices_tmp As v
- ON ST_DWithin(v.the_geom, b.the_geom, 10000)
- ORDER BY ST_Distance(v.the_geom, b.the_geom)
- LIMIT 1;'
- $result = pg_query($sql) or die ('Query failed: ' . pg_last_error());
- // Printing results in HTML
- /*echo "<table>\n";
- while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
- echo "\t<tr>\n";
- foreach ($line as $col_value) {
- echo "\t\t<td>$col_value</td>\n";
- }
- echo "\t</tr>\n";
- }
- echo "</table>\n";*/
- while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
- foreach ($line as $col_value) {
- echo "$col_value";
- }
- };
- // Free resultset
- pg_free_result($result);
- // Closing connection
- pg_close($dbconn);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement