// // Copyright (C) 2007 Refractions Research, Inc. // // This library is free software; you can redistribute it and/or // modify it under the terms of version 2.1 of the GNU Lesser // General Public License as published by the Free Software Foundation. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // #include #include #include #include #include #include #include #include "fdoutility.h" using namespace fdoutility; int main(int argc, char* argv[]) { try { std::wstring provider(L"OSGeo.PostGIS.3.2"); // Connection string with datastore specified std::wstring ds(L"myds"); std::wstring connStr(L"service=fdo_test;username=mloskot;password=pantera;"); // Create connection FdoPtr conn = fdoutility::create_connection(provider); connStr += L"datastore=" + ds; conn->SetConnectionString(connStr.c_str()); // Open connection FdoConnectionState state = conn->Open(); std::wcout << "Connection state: " << state << std::endl; // Create command FdoPtr cmd; cmd = static_cast(conn->CreateCommand(FdoCommandType_GetSpatialContexts)); assert(0 != cmd); // Configure command cmd->SetActiveOnly(true); // Execute command FdoPtr reader = cmd->Execute(); FdoPtr gf(FdoFgfGeometryFactory::GetInstance()); // Read command execution results int cnt = 0; while (reader->ReadNext()) { FdoPtr env = NULL; env = gf->CreateGeometryFromFgf(reader->GetExtent()); ++cnt; std::wcout << std::setw(2) << cnt << L". " << reader->GetName() << std::endl << std::make_pair("Description", reader->GetDescription()) << std::make_pair("CoordSysName", reader->GetCoordinateSystem()) << std::make_pair("WKT", reader->GetCoordinateSystemWkt()) << L"\nExtent:\n" << L"\tMin X: " << env->GetEnvelope()->GetMinX() << L"\tMin Y: " << env->GetEnvelope()->GetMinY() << L"\tMax X: " << env->GetEnvelope()->GetMaxX() << L"\tMax Y: " << env->GetEnvelope()->GetMaxY() << std::endl; } std::cout << "Number of contexts: " << cnt << std::endl; // Close connection (optional) conn->Close(); } catch (FdoException* ex) { std::wcout << L"*** FDO Error:\n"; int i = 5; FdoException* nex = ex; while (NULL != nex) { const wchar_t* msg = nex->GetExceptionMessage(); if (NULL == msg) { msg = L"NO MESSAGE"; } std::wcout << std::setw(++i) << L"*** " << msg << std::endl; FdoException* p = nex; nex = nex->GetCause(); p->Release(); } } catch(std::exception& ex) { std::cout << "*** Std Error: " << ex.what() << std::endl; } catch(...) { std::cout << "*** Undefined error!\n" << std::endl; } return 0; }