The Query for getting data from the Postgres database

Description: This part of the project was to create queries to Postgres Database. A PHP back-end script is used to connect to the database and execute the query. Further, the results of the query are sent to WebGL as JSON objects.

The PHP code is as follows:

      $hostDb = "host=localhost";
      $dbName = "dbname=osm";
      $userDb = "user=sreenidhi";
      $pgCon = pg_connect("$hostDb $dbName $userDb");

The above code connects to the database using the DB parameters specified, with the help of pg_connect() function. The query is as follows:

       SELECT name, ST_AsText(ST_Transform(way,4326))
      FROM planet_osm_polygon
       WHERE ST_Intersects(way, ST_Transform(ST_MakeEnvelope(($lon_min),
       ($lat_min), ($lon_max),
       ($lat_max), 94326), 900913));

Here, the MakeEnvelope constructor creates a bounding box using the parameters specified- they are calculated by getting the current geographical position coordinates from the browser and adding and subtracting a specific value from them to calculate the minimums and maximums. The Transform constructor transforms the way geometry into a way that can be read, which is calculated by specifying the SRID for WGS84 projection, which is 4326. The AsText constructor, converts the data into a Well-Known Text representation (WKT).