Chinaunix首页 | 论坛 | 博客
  • 博客访问: 721345
  • 博文数量: 33
  • 博客积分: 10012
  • 博客等级: 上将
  • 技术积分: 1365
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-15 09:11
文章分类
文章存档

2009年(10)

2008年(23)

我的朋友

分类: C/C++

2008-05-26 13:20:31


// fdotest.cpp : 定义控制台应用程序的入口点。

//


#include "stdafx.h"
#include "Fdo.h"
#include <cassert>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>

#define LOCATION L"e://fdotest"

//FdoPtr mConnection;


void apply_schema()
{
    std::wstring provider(L"OSGeo.SHP.3.3");
    std::wstring ds(L"st_zd");
    std::wstring connStr(L"DefaultFileLocation=E:\\shp\\st_zd.shp;TemporaryFileLocation=E:\\shp");
    try
    {
        //获取注册的驱动


        IProviderRegistry* providerReg = FdoFeatureAccessManager::GetProviderRegistry();

        //创建一个连接管理器


        IConnectionManager* connManager = FdoFeatureAccessManager::GetConnectionManager();

        //创建一个连接


        FdoIConnection* mConnection = connManager->CreateConnection(provider.c_str());

        FdoString* fileName = L"test";

        mConnection->Close ();

        FdoPtr<FdoIConnectionInfo> cinfo = mConnection->GetConnectionInfo();
        FdoPtr<FdoIConnectionPropertyDictionary> didc = cinfo->GetConnectionProperties();
        didc->SetProperty(L"DefaultFileLocation", LOCATION);
        didc->SetProperty(L"TemporaryFileLocation",L"");

        mConnection->Open();
        //Generating default data property

        FdoPtr<FdoDataPropertyDefinition> featid = FdoDataPropertyDefinition::Create(L"FeatId",L"Default identity property");
        featid->SetDataType(::FdoDataType_Int32);
        featid->SetIsAutoGenerated(false);
        featid->SetNullable(false);
    
        //Generating default geometric property

        FdoPtr<FdoGeometricPropertyDefinition> geometry=FdoGeometricPropertyDefinition::Create(L"Geometry",L"Default geometry property");
        geometry->SetGeometryTypes(FdoGeometricType_Point);
    
        //Generating default feature class

        FdoPtr<FdoFeatureClass> featureclass1=FdoFeatureClass::Create(L"FeatureClass1",L"Default feature class");
        FdoPtr<FdoPropertyDefinitionCollection> properties=featureclass1->GetProperties();
        properties->Add(featid);
        properties->Add(geometry);
        FdoPtr<FdoDataPropertyDefinitionCollection> identifier=featureclass1->GetIdentityProperties();
        identifier->Add(featid);
        featureclass1->SetGeometryProperty(geometry);

        //Generating default schema

        FdoPtr<FdoFeatureSchema> schema1=FdoFeatureSchema::Create(L"Schema1",L"Default schema");
        FdoClassesP(schema1->GetClasses()->Add(featureclass1));

        //FdoPtr schema = schema1->GetItem(0);

        FdoPtr<FdoClassCollection> coll = schema1->GetClasses();
        FdoPtr<FdoClassDefinition> def = coll->GetItem(0);
        def->SetName(fileName);
    
        FdoPtr<FdoIApplySchema> apply = (FdoIApplySchema*) mConnection->CreateCommand(FdoCommandType_ApplySchema);
        apply->SetFeatureSchema(schema1);
        apply->Execute();
    }
    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;
     }
}

int _tmain(int argc, _TCHAR* argv[])
{
    apply_schema();
    return 0;
}

阅读(2538) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-03-27 17:32:37

如果创建sqlite的数据库的话,怎么总是提示 *** File does not exist!