Create DataStore using FDO API in Map 3D

本文涉及的产品
RDS SQL Server Serverless,2-4RCU 50GB 3个月
推荐场景:
云数据库 RDS SQL Server,基础系列 2核4GB
简介:


A data store is a repository of an integrated set of objects. The objects in a data store are modeled either by classes or feature classes defined within one or more schemas. For example, a data store may contain data for both a LandUse schema and a TelcoOutsidePlant schema. Some data stores can represent data in only one schema, while other data stores can represent data in many schemas (for example, RDBMS-based data stores, such as MySQL).

In this sample, I will create a data store in SQL Server 2008 using OSGEO FDO Provider for SQL Server Spatial. By default the Sql Server, Oracle, MySQL, and SDF providers create data stores that contain FDO metadata. By default the SQL Server Spatial provider creates a data store that does not contain the FDO metadata. To make this provider create a data store that does contain the FDO metadata, you must set the IDataStorePropertyDictionary property IsFdoEnabled to true. The PostGIS provider creates a data store without the FDO metadata.

A provider uses the FDO metadata to:

  • Assign a default spatial context to a Geometric Property Definition during schema creation.

 

Firstly, create a class library in Visutal Studion 2010 or 2008, add references to AutoCAD managed assembly and FDO assebmly, you can find them in Map 3D/Civil 3D installation folder and FDO\bin folder

C:\Program Files\Autodesk\AutoCAD Civil 3D 2011

C:\Program Files\Autodesk\AutoCAD Civil 3D 2011\FDO\bin

 

image 

 

By default the SQL Server Spatial provider creates a data store that does not contain the FDO metadata. To make this provider create a data store that does contain the FDO metadata, we need set parameter IsFdoEnabled to true. the value '”true” is case sensetive.

code snippet goes as below:

 [CommandMethod("CreateDataStore")]
public void CreateDataStore()
{
ICreateDataStore createDS = m_pConnection.CreateCommand(CommandType.CommandType_CreateDataStore) as ICreateDataStore;

IDataStorePropertyDictionary properties = createDS.DataStoreProperties;
properties.SetProperty("DataStore", "TestDataStore");
properties.SetProperty("Description", "This is a test datastore");
properties.SetProperty("IsFdoEnabled", "true"); // case sensitive

createDS.Execute();
}

 

Here is the screen-shot we can see from SQL Server Managemet Studio.

clip_image002

 

Following code enable us to select fdo provider and input parameter at run time.

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();
        }
}

 

 

Cheers,

Daniel  峻祁连

作者: 峻祁连
邮箱:junqilian@163.com 
出处: http://junqilian.cnblogs.com 
转载请保留此信息。



本文转自峻祁连. Moving to Cloud/Mobile博客园博客,原文链接:http://www.cnblogs.com/junqilian/archive/2010/06/13/1757950.html ,如需转载请自行联系原作者
相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS&nbsp;SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/sqlserver
相关文章
|
7月前
|
分布式计算 JavaScript 前端开发
JS中数组22种常用API总结,slice、splice、map、reduce、shift、filter、indexOf......
JS中数组22种常用API总结,slice、splice、map、reduce、shift、filter、indexOf......
|
4月前
|
存储 API
Map常用API
Map常用API
39 2
|
4月前
|
存储 算法 Java
Go 通过 Map/Filter/ForEach 等流式 API 高效处理数据
Go 通过 Map/Filter/ForEach 等流式 API 高效处理数据
|
5月前
|
JavaScript API
js【最佳实践】遍历数组的八种方法(含数组遍历 API 的对比)for,forEach,for of,map,filter,reduce,every,some
js【最佳实践】遍历数组的八种方法(含数组遍历 API 的对比)for,forEach,for of,map,filter,reduce,every,some
94 1
|
5月前
|
JSON JavaScript API
JS【详解】Map (含Map 和 Object 的区别,Map 的常用 API,Map与Object 的性能对比,Map 的应用场景和不适合的使用场景)
JS【详解】Map (含Map 和 Object 的区别,Map 的常用 API,Map与Object 的性能对比,Map 的应用场景和不适合的使用场景)
143 0
|
7月前
|
API C# 图形学
【Unity 3D】常见API的讲解以及在C#脚本中的执行(附源码)
【Unity 3D】常见API的讲解以及在C#脚本中的执行(附源码)
170 1
|
7月前
|
存储 算法 Java
【Java 集合框架API接口】Collection,List,Set,Map,Queue,Deque
【Java 集合框架API接口】Collection,List,Set,Map,Queue,Deque
101 0
|
定位技术 API 容器
百度地图API开发:map.getDistance计算两点之间的距离(直线距离)
百度地图API开发:map.getDistance计算两点之间的距离(直线距离)
960 0
|
API
java202303java学习笔记第三十二天Map集合常见api
java202303java学习笔记第三十二天Map集合常见api
69 0
java202303java学习笔记第三十二天Map集合常见api2
java202303java学习笔记第三十二天Map集合常见api2
67 0