【发布时间】:2010-11-08 13:36:02
【问题描述】:
我想检索存储在 postgres 数据库。 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))
顶点列的类型是多边形。
我正在使用 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 是如何 有效,但我坚持使用多边形类型。我们实际上只需要一个简单的 在 Postgres 中存储我们的多边形,但我不知道如何访问它们 使用 libpqxx。
【问题讨论】:
标签: c++ postgresql polygon libpqxx