[postgis-users] C++ and Postgis
Maxime van Noppen
maxime at altribe.org
Tue Nov 24 00:58:47 PST 2009
Pedro Doria Meunier wrote:
> How does one deal with Postgis geom fields in C++ ?
> Google hasn't offered much help so far.
Hi, I know you got a better answer to your problem but just in case it
might help someone here is how I transfer data from postgis to libpq / C++ :
{
pqxx::connection db("host=.... dbname=... user=...");
pqxx::work xaction(db, "gis");
const pqxx::result& res = xaction.exec("SELECT geom FROM sometable;");
// by default, geom is in WKB
std::istringstream istr(res[0].c_str());
geos::geom::GeometryFactory factory;
geos::io::WKBReader wkbr(factory);
geos::geom::Geometry* geom = wkbr.readHEX(istr);
// use geom.
std::cout << "geom is a " << geom->getGeometryType() << std::endl;
delete geom;
}
--
Maxime
More information about the postgis-users
mailing list