Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <?php
  2. // Connecting, selecting database
  3. $dbconn = pg_connect("host=localhost  port=5432 dbname=routing user=postgres password=p8dx2780")
  4.     or die('Could not connect: ' . pg_last_error());
  5.  
  6. // Performing SQL query
  7. //$query = 'SELECT st_asgeojson(st_union(the_geom)) FROM export';
  8. //$result = pg_query($query) or die('Query failed: ' . pg_last_error());
  9. $x = $_GET["x"];
  10. $y = $_GET["y"];
  11.  
  12. $sql = 'SELECT ST_AsGeoJSON(v.the_geom)
  13. FROM (SELECT ST_SetSRID(ST_Point('.$y.','.$x.'),
  14. 900913) As the_geom) As b LEFT JOIN vertices_tmp As v
  15. ON ST_DWithin(v.the_geom, b.the_geom, 10000)
  16. ORDER BY ST_Distance(v.the_geom, b.the_geom)
  17. LIMIT 1;'
  18.  
  19. $result = pg_query($sql) or die ('Query failed: ' . pg_last_error());
  20.  
  21. // Printing results in HTML
  22. /*echo "<table>\n";
  23. while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
  24.     echo "\t<tr>\n";
  25.     foreach ($line as $col_value) {
  26.         echo "\t\t<td>$col_value</td>\n";
  27.     }
  28.     echo "\t</tr>\n";
  29. }
  30. echo "</table>\n";*/
  31.  
  32. while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
  33.     foreach ($line as $col_value) {
  34.         echo "$col_value";
  35.     }
  36. };
  37.  
  38. // Free resultset
  39. pg_free_result($result);
  40.  
  41. // Closing connection
  42. pg_close($dbconn);
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement