我想检索存储在中的多边形点 Postgres 数据库 数据库的内容是:
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。
最佳答案
与此同时,我将使用以下方法对字符串进行标记:
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(",()");
tokenizer tokens(str_coordinates, sep);
for (tokenizer::iterator tok_iter = tokens.begin();
tok_iter != tokens.end(); ++tok_iter)
{
std::cout << "x:<" << *tok_iter << "> ";
++tok_iter;
std::cout << "y:<" << *tok_iter << "> " << endl;
}
关于c++ - 如何使用 Libpqxx 访问存储在 Postgres 中的多边形点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1089991/