1

I'm a beginner in this field and tried to display the PostGIS database data in localhost. I used select query in my code, so the table got displayed. I want to display the geographical points in a map overlay or in GeoMoose. I'm attaching the code which I used to display the table. Can anyone help me?

<!DOCTYPE html>
<html>
<head></head>
<body bgcolor="white">
<?php
  class assets {
    public $gid;
    public $id;
    public $name;
    public $main;
    public $asset_name;
    public $assetname;
    public $geom;

    //Database Variables

    public $connection;
    public function __construct()     {
        $this->connection = pg_connect("host=localhost port=5432 dbname=postgis user=postgres password=1234") or print("cant connect");
    }
    public function __destruct() { 
    }
    public function create() {
    }
    public function read() {
          $result = pg_query($this->connection, "SELECT gid,id, name, main,asset_name,assetname,geom FROM assets");
          if (!$result) {
              echo "An error occured.\n";
              exit;
          } else {
          echo "<table border=1>";
          echo "<tr><td>gID</td><td>ID</td><td>Name</td>
                    <td>Main</td>     <td>asset_name</td>      <td>assetname</td>      <td>geom</td></tr>";

                   while ($row = pg_fetch_row($result))  {
                          echo "<tr>";
                          echo "<td valign=top>".$row[0]."</td>";
                          echo "<td valign=top>".$row[1]."</td>";
                          echo "<td valign=top>".$row[2]."</td>";
                              echo "<td valign=top>".$row[3]."</td>";
                                  echo "<td valign=top>".$row[4]."</td>";
                                      echo "<td valign=top>".$row[5]."</td>";
                                      echo "<td valign=top>".$row[6]."</td>";
                          echo "</tr>";
                   }

          echo "</table>";
          } 

    pg_close($this->connection);
    }
    public function update(){
    }
    public function delete(){
    }
}
$myAssets = new assets();
$myAssets->read();
?>   
</body>
</html>
4
  • Sorry for attaching code in this way.I'm new to this and so dont know where to attach the code
    – user43112
    Commented Mar 7, 2015 at 5:02
  • You need to do a few things ot get an answer. 1. format your code so it is readable, in an indented structure so people can read it. Secondly, state the language you are working in and ad it as a tag. there isa formatting help button immediatly above th ebox where you entered you question, and please check out the help at the top of the page. Commented Mar 7, 2015 at 5:24
  • the language used is php
    – user43112
    Commented Mar 7, 2015 at 5:55
  • What's with the weird spacing in your prose and code? Your random use or misuse of the space bar, in this and your other questions, won't win you many friends.
    – Martin F
    Commented Apr 11, 2015 at 21:25

2 Answers 2

1

What you are looking for is a way to represent binary geometry as a string so you can easily pass it to the map. See PostGIS geometry outputs section of the docs. You might want to look into GeoJSON a bit.

3
  • Thank you sir. I'm trying to plot the points in geomoose
    – user43112
    Commented Mar 8, 2015 at 9:46
  • @user43112 - Is that an acceptance of, or a rebuttal to, the answer?
    – Martin F
    Commented Apr 11, 2015 at 21:26
  • 1
    Actually i didnt get the result with that explanation.Because the answer gave only an idea about postgis geometry conversion and the query which i asked was not that.but the answer given for this question helped me for developing further.so thanks for that.
    – user43112
    Commented Apr 17, 2015 at 8:54
0

I think you have some extra spaces in your SQL call, just delete them and try again. Try to get extra information with console.log() and firebug or some other debugging tools. The better the verbose mode you use, the easier the way you solve your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.