[Libpqxx-general] Polygon data type in postgres

Mark Gabriel Paylaga mpaylaga at gmail.com
Mon Jul 6 08:08:43 UTC 2009


Hello all,

I'm trying to retrieve the points of a polygon that are stored in the
postgres db.
The contents of the db are:
 polygonid |
vertices
-----------+---------------------------------------------------------------------
         2 |
((1,0),(1.5,-1),(2,-1),(2,1),(1,1),(0,0),(0,2),(3,2),(3,-2),(1,-2))
         3 | ((3,3),(4,4))
         4 | ((3,3),(4,4),(5,5))
         5 | ((0,1))

The vertices column is of type Polygon.

I'm using libpqxx library for C++.

Suppose I want to retrieve and access the points in the vertices column,
I would execute these statements in C++:

        result R = W.exec ("select * from polygon_tbl");
        for (result::const_iterator r = R.begin();
             r != R.end();
             ++r)
        {
           int x = 0;
           cout << "Polygon ID: " << r[0].to(x) << endl;

           //Suppose i would like to print the first point of every polygon,
           //how would i access it?
           cout << "First vertex: " << r[0][0] << endl;    ???

           //Or suppose i would like to print the first x coordinate of
every polygon,
           //how would i access it?
           cout << "First x coordinate: " << r[0][0][0] << endl; ???? (am
just guessing here..)

        }

Sorry I'm very new to libpqxx. I've pretty much understood how the libpqxx
works but I'm stuck with the Polygon types. We actually just need a simple
storage for our polygons in Postgres but I'm not sure how to access them
using libpqxx.

A little help would be nice... :)

Best regards,
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://pgfoundry.org/pipermail/libpqxx-general/attachments/20090706/fe2ccb22/attachment.html>


More information about the Libpqxx-general mailing list