Chris Pollett > Students > Pundi Muralidharan

    Print View



    [CS 297 Proposal]

    [Deliverable 1 - WebGL Program: The Logic Behind]

    [Deliverable 2 - The Study of OSM Data and Vector Tiles]

    [Deliverable 3 - Importing OSM Data into Postgres Database]

    [Deliverable 4 - Study of Current Tile Generators in Trend]

    [CS 297 Report - PDF]

    [CS 298 Proposal]

    [CS 298 Report-Intermediate - PDF]

    [CS 298 - Summary of Intermediate Results - PDF]

    [The Project Idea]

    [The Map Query]

    [The WebGL Shaders]

    [The Final Map]

    [CS 298 Report - PDF]

    [CS 298 Presentation - PDF]

    [CS 298 Project Source Code - ZIP]


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).