我想检索存储在 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))
vertices 列的类型为 Polygon。
我正在为 C++ 使用 libpqxx 库。
假设我想检索和访问 vertices 列中的点,我将在 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 访问它们。