SuperMap8C C#二次开发,创建矢量数据集、字段

基于SuperMap8C二次开发,C#语言,创建点、线、面等数据集、字段

public void CreateDataSetTest()
        {
            DatasourceConnectionInfo datasourceConnectinfo = new DatasourceConnectionInfo();
            datasourceConnectinfo.EngineType = EngineType.SQLPlus;//数据库类型,SqlServer
            datasourceConnectinfo.Server = "127.0.0.1";//服务器名称
            datasourceConnectinfo.Database = "TestData";// 数据库名称
            datasourceConnectinfo.Alias = "TestData";//数据库别名
            datasourceConnectinfo.User = "sa";  //数据库用户;
            datasourceConnectinfo.Password = "123456";//数据库密码;
            datasourceConnectinfo.Driver = "SQL Server";//数据库驱动

            //打开地图的工作空间
            Workspace mWorkspace = SuperMap.Desktop.Application.ActiveApplication.Workspace;
            string strWorkSpaceName = System.Windows.Forms.Application.StartupPath + @"\Data\数据.smwu";
            WorkspaceConnectionInfo connectinfo = new WorkspaceConnectionInfo(strWorkSpaceName);
            mWorkspace.Open(connectinfo);

            //打开连接
            Datasource datasource = mWorkspace.Datasources.Open(datasourceConnectinfo);

            //创建矢量数据集
            DatasetVectorInfo datasetTest = new DatasetVectorInfo();// 设置矢量数据集的信息
            datasetTest.Type = DatasetType.Region;//数据集类型(点、线、面、属性等)
            datasetTest.IsFileCache = true;
            datasetTest.Name = "测试面数据集";//数据集名称
            datasource.Datasets.Create(datasetTest);// 创建矢量数据集

            //创建字段
            DatasetVector dataset_TestRegion = (DatasetVector)SimpleWorkSpace.m_workspace.Datasources[DBSwmConn.m_Alias].Datasets[Model.DataSetName.XJXZQ];
            FieldInfos Region_fieldInfos = dataset_TestRegion.FieldInfos;

            FieldInfo field_ID = new FieldInfo("ID", FieldType.Int32); //标识
            field_ID.Caption = "标识";//字段别名
            field_ID.IsRequired = true;//是否为必填字段 如果字段为必填字段则为true,否则为false,默认值为false。

            FieldInfo field_User = new FieldInfo("Ueser", FieldType.Text);
            field_User.Caption = "用户";
            field_User.IsRequired = false; 

            FieldInfo field_Remark = new FieldInfo("Remark", FieldType.Text);//备注
            field_Remark.Caption = "备注";
            field_Remark.DefaultValue = "备注信息";//默认值

            //将字段添加
            Region_fieldInfos.Add(field_ID);
            Region_fieldInfos.Add(field_User);
            Region_fieldInfos.Add(field_Remark);
        }


你可能感兴趣的:(SuperMap8C二次开发)