postgres db に格納されているポリゴンのポイントを取得したいと考えています。db の内容は次のとおりです。
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))
頂点列のタイプは Polygon です。
C++ 用の libpqxx ライブラリを使用しています。
頂点列のポイントを取得してアクセスしたいとします。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..)
}
申し訳ありませんが、libpqxx は初めてです。libpqxx がどのように機能するかはほぼ理解できましたが、Polygon 型に固執しています。実際には、Postgres にポリゴン用の単純なストレージが必要なだけですが、libpqxx を使用してポリゴンにアクセスする方法がわかりません。