博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用FDO API连接到各种数据源
阅读量:6760 次
发布时间:2019-06-26

本文共 4437 字,大约阅读时间需要 14 分钟。

Map 3D可以通过FDO技术连接到各种数据源,包括SHP文件,SDF文件,MySQL,SQL Server Spatial,Oracle等等。当然了,连接到不同数据源肯定有不同的参数,或者理解成连接字符串的组成部分。那这些参数都是什么呢?我们可以通过下面一段代码来深入理解这个参数:

闲话不多少,直接上代码,你可以在Map 3D中运行一下就会发觉他的奥妙:

using Autodesk.AutoCAD;using Autodesk.AutoCAD.Runtime;using OSGeo.FDO;using OSGeo.FDO.Commands;using OSGeo.FDO.Commands.Schema;using OSGeo.FDO.Connections;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.ApplicationServices;using OSGeo.FDO.Schema;using OSGeo.FDO.Connections.Capabilities;using OSGeo.FDO.ClientServices;using OSGeo.FDO.Commands.DataStore;    public class Class1    {        IConnection m_pConnection = null;        Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;        FeatureClass m_baseClass;        FeatureClass m_riverClass;        ProviderCollection m_Providers;        string m_sProviderName;        [CommandMethod("connect")]        public void Connect()        {            IConnectionManager connMgr;            int index;            Provider provider;            IProviderRegistry registry = FeatureAccessManager.GetProviderRegistry();            m_Providers = registry.GetProviders();            for (int i = 0; i < m_Providers.Count; i++)            {                provider = m_Providers[i];                ed.WriteMessage(string.Format("FDO support provider {0}, its index is {1} \n", provider.Name, i));            }            PromptIntegerResult intRes = ed.GetInteger("please input the provider's index");            if (intRes.Status == PromptStatus.OK)            {                index = intRes.Value;               provider = m_Providers[index];                m_sProviderName = provider.Name;                string shortName = provider.Name.Split('.')[1];                try                {                    connMgr = FeatureAccessManager.GetConnectionManager();                    m_pConnection = connMgr.CreateConnection(m_sProviderName);                    IConnectionInfo connInfo = m_pConnection.ConnectionInfo;                    IConnectionPropertyDictionary properties = connInfo.ConnectionProperties;                    InputParametersValue(properties);                    ConnectionState connState = m_pConnection.Open();                                        ed.WriteMessage("connect status is "+connState.ToString() + "\n");                }                catch (OSGeo.FDO.Common.Exception exception)                {                    ed.WriteMessage("There are some exceptions with message : " + exception.Message + "\n");                }                            }            else            {                ed.WriteMessage("you did not select a correct provider , exit \n");                return;            }        }        [CommandMethod("DisConnect")]        public void CloseConnection()        {            m_pConnection.Close();        }        private void InputParametersValue(IConnectionPropertyDictionary properties)        {            string[] propertiesNames = properties.PropertyNames;            foreach (string name in propertiesNames)            {                PromptStringOptions pso = new PromptStringOptions("Please input the value for \"" + name + "\":");                PromptResult psr = ed.GetString(pso);                if (properties.IsPropertyRequired(name))                {                    while (psr.Status != PromptStatus.OK)                    {                        ed.WriteMessage(string.Format("Parameter \"{0}\" is required, please input value again\n", name));                        psr = ed.GetString(pso);                    }                    properties.SetProperty(name, psr.StringResult);                }            }        }        private void ListPropertiesParameters(IDataStorePropertyDictionary properties)        {            foreach (string name in properties.PropertyNames)            {                ed.WriteMessage(name + "\n");            }        }        [CommandMethod("CreateDataStore")]        public void CreateDataStore()        {            ICreateDataStore createDS = m_pConnection.CreateCommand(CommandType.CommandType_CreateDataStore) as ICreateDataStore;            IDataStorePropertyDictionary properties = createDS.DataStoreProperties;            InputParametersValue(properties);            createDS.Execute();        }}
作者:
邮箱:junqilian@163.com 
出处:  
转载请保留此信息。
本文转自峻祁连. Moving to Cloud/Mobile博客园博客,原文链接:http://www.cnblogs.com/junqilian/archive/2012/05/15/2501140.html
,如需转载请自行联系原作者
你可能感兴趣的文章
小程序实现长按录音,上划取消发送
查看>>
php实现共享内存进程通信函数之_shm
查看>>
Java多线程基础(一)——线程与锁
查看>>
01 【零基础入门】html学习笔记(1)
查看>>
没有对象?new一个!
查看>>
实战PHP数据结构基础之双链表
查看>>
性感慕课-在线被爬
查看>>
【跃迁之路】【437天】刻意练习系列196—Java基础练习(线程)(2018.04.18)
查看>>
es6学习
查看>>
Python每日一练0012
查看>>
Vue.js入门教程-methods
查看>>
STL二级空间配置器
查看>>
使用vue写的计算器demo
查看>>
SQL Server 学习 SQL 语句 ( 一 )
查看>>
leetcode 16 3Sum Closest
查看>>
fetch和Promise
查看>>
Tin显示效果的美化
查看>>
NPM酷库:string-random,生成随机字符串
查看>>
简陋的swift carthage copy-frameworks 辅助脚本
查看>>
Just for fun——Slim借力Swoole
查看>>