Polygon data type

From: Mark Gabriel Paylaga <mpaylaga(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org, peterw(at)borstad(dot)com
Subject: Polygon data type
Date: 2009-07-08 06:30:23
Message-ID: d2f72a1b0907072330n3ef56079m4463b72f3daaba20@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello all,

I know that this is the postgres forum and not the libpqxx forum (I've been
there but no answer yet).

I want 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))
4 | ((3,3),(4,4),(5,5))

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[1][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[1][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. I know I can parse it as a string using r[1].c_str(), but is
this the proper way to do it (parsing the text)? Or is there a container
that I should use to store the vertices and access them using the container
?
best regards,
mark

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2009-07-08 07:02:19 Re: Bug in ecpg lib ?
Previous Message Yar Tikhiy 2009-07-08 05:17:44 Re: Warm standby: 1 to N