[postgis-users] PHP access to PostGIS

Stephen Woodbridge woodbri at swoodbridge.com
Thu Mar 10 18:51:18 PST 2005


Hi all,

I new to working with PostGIS. I'm using PHP and I need to get my 
ployline into a PHP array. What is the best way to do this?

What I'm doing so far is:

     // get the segment and offset the point right/left
     // retrieve the segment geometry

     $sql = "select AsText(geom) as geom from geocode" .
            " where id = $this->oRefId";

     // execute SQL query
     $result = @pg_query($this->conn, $sql);
     if (!$result) {
       return false;
     }

     // get the number of rows in the resultset - must be one
     $rows = pg_num_rows($result);
     if ($rows < 1) {
       return false;
     }

     // read the points
    $row = pg_fetch_array($result, 0, PGSQL_ASSOC);
print_r($row);
echo "<br>\n";

Which gives me:
Array ( [geom] => LINESTRING(-73.338249206543 
41.1630020141602,-73.3395233154297 41.1648445129395) )

So I'm wondering if I need to parse the text, or if there is an easier 
way this into a PHP structure, like:

$line = [ [-73.338249206543,  41.1630020141602],
           [-73.3395233154297, 41.1648445129395] ];

or some other array structure.

-Steve W.



More information about the postgis-users mailing list