// // 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 "fdoutility.h" using namespace fdoutility; using namespace std; int main(int argc, char* argv[]) { try { std::wstring provider(L"OSGeo.PostGIS.3.2"); // Connection string with datastore specified std::wstring ds(L"test"); std::wstring connStr(L"service=fdo_test;username=mloskot;password=pantera;"); //std::wstring connStr(L"service=world@192.168.1.101;username=mloskot;password=pantera;"); // Connect FdoPtr conn = fdoutility::create_connection(provider); connStr += L"datastore=" + ds; conn->SetConnectionString(connStr.c_str()); FdoConnectionState state = conn->Open(); cout << "Connection state: " << state << endl; // Create command FdoPtr cmd; cmd = static_cast(conn->CreateCommand(FdoCommandType_Select)); assert(0 != cmd); // Execute command cout << "Executing FdoISelect command...\n"; FdoStringP className("FdoPostGIS:"); className += ds.c_str(); className += L"~"; className += L"mypoint"; cmd->SetFeatureClassName(static_cast(className)); FdoPtr reader = cmd->Execute(); cout << "Reading features...\n"; FdoPtr geomFactory(FdoFgfGeometryFactory::GetInstance()); // Get the feature class object and its properties FdoPtr classDef(reader->GetClassDefinition()); FdoPtr props(classDef->GetProperties()); while (reader->ReadNext()) { // Iterate through the class properties for (FdoInt32 i = 0; i < props->GetCount(); i++) { FdoPtr propDef(props->GetItem(i)); FdoStringP propName(propDef->GetName()); wcout << i << ". " << propName << endl; // Read the property characteristics and data if (FdoPropertyType_DataProperty == propDef->GetPropertyType()) { FdoDataPropertyDefinition* dataPropDef = NULL; dataPropDef = static_cast(propDef.p); FdoDataType dataType = dataPropDef->GetDataType(); switch (dataType) { case FdoDataType_Boolean: wcout << L" Value: " << reader->GetBoolean(propName) << endl; break; case FdoDataType_Int32: wcout << L" Value: " << reader->GetInt32(propName) << endl; break; case FdoDataType_Decimal: case FdoDataType_Double: case FdoDataType_Single: wcout << L" Value: " << std::fixed << reader->GetDouble(propName) << endl; break; case FdoDataType_String: wcout << L" Value: " << reader->GetString(propName) << endl; break; default: wcout << L" Value: unknown type\n"; } } else if (FdoPropertyType_GeometricProperty == propDef->GetPropertyType()) { FdoPtr fgfBytes(reader->GetGeometry(propName)); FdoPtr geometry(geomFactory->CreateGeometryFromFgf(fgfBytes)); //wcout << L"Value: " << geometry->GetText() << endl; } } cout << "--------------------------------------\n"; } // Close connection (usually optional) reader->Close(); conn->Close(); cout << "FdoIConnection::Close()\n"; cout << " State: " << conn->GetConnectionState() << endl; } 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; }