// // 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 std; 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"public"); std::wstring connStr(L"service=test@localhost;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_ApplySchema)); assert(0 != cmd); // Create feature schema, classes and properties FdoPtr fSchema = FdoFeatureSchema::Create(L"FdoPostGIS", L"Test default schema "); FdoPtr fClass = FdoFeatureClass::Create(L"Shops", L"Test class of shopts"); fClass->SetIsAbstract(false); FdoPtr props = fClass->GetProperties(); FdoPtr idProps = fClass->GetIdentityProperties(); FdoPtr propIdent = FdoDataPropertyDefinition::Create(L"AttrId", L"id"); propIdent->SetDataType(FdoDataType_Int64); propIdent->SetNullable(false); propIdent->SetIsAutoGenerated(true); props->Add(propIdent); idProps->Add(propIdent); FdoPtr propName = FdoDataPropertyDefinition::Create(L"AttrName", L"Name"); propName->SetDataType(FdoDataType_String); propName->SetLength(64); propName->SetNullable(true); propName->SetIsAutoGenerated(false); props->Add(propName); // create a geometric property FdoPtr propGeom; propGeom = FdoGeometricPropertyDefinition::Create(L"the_geom", L"Sample Geometric Property Description"); propGeom->SetGeometryTypes(FdoGeometricType_Point); propGeom->SetReadOnly(false); propGeom->SetHasMeasure(true); propGeom->SetHasElevation(false); props->Add(propGeom); fClass->SetGeometryProperty(propGeom); FdoPtr fClasses = fSchema->GetClasses(); fClasses->Add(fClass); // Execute command cmd->SetFeatureSchema(fSchema); cmd->Execute(); // Release resources conn->Close(); return 0; } 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; }