zoukankan      html  css  js  c++  java
  • 使用FDO API连接到各种数据源

    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(); } }
  • 相关阅读:
    Mac Sublime Text 3 配置Python环境及安装插件
    iOS 简单易用的二维码扫描及生成二维码三方控件LFQRCode,可灵活自定义UI
    iOS 自定义相机带拍摄区域边框及半透明遮罩层(含源码)
    Xcode8 不能显示blame,show blame for line 灰色不可点解决办法
    github + SourceTree管理自己的库并上传到cocoapods及各种坑的解决办法
    Mysql查询的一些操作(查表名,查字段名,查当月,查一周,查当天)
    SqlServer表结构查询
    NET(C#):XmlArrayItem特性和XmlElement特性在序列化数组的差别
    Git常用命令
    MySQL添加用户、删除用户与授权
  • 原文地址:https://www.cnblogs.com/junqilian/p/2501140.html
Copyright © 2011-2022 走看看