• AE DataTable转换为ITable(内存工作空间中)


     public static ITable ToITable(DataTable mTable)
            {
                try
                {
                    #region 新建表字段
                    IFields fields = new FieldsClass();
                    IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
    
                    for (int i = 0; i < mTable.Columns.Count; i++)
                    {
                        IField pField = new FieldClass();
                        IFieldEdit fieldEdit = (IFieldEdit)pField;
                        fieldEdit.Name_2 = mTable.Columns[i].ColumnName;
                        fieldEdit.AliasName_2 = mTable.Columns[i].ColumnName; 
                        //这里根据实际情况设置 
                        if (i == 0)
                        {
                            fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
                        }
                        else
                        {
                            fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                        }
                        fieldEdit.Editable_2 = true;
                        fieldsEdit.AddField(pField);
                    }
                    #endregion
                      
                    // 实例化内存工作空间工厂
                    IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
                
                    // 创建内存工作空间
                    IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0);
                    IName name = (IName)workspaceName;
    
                    // 通过name对象打开工作空间
                    IWorkspace workspace = (IWorkspace)name.Open();
                    IFeatureWorkspace pFWS = workspace as IFeatureWorkspace;
    
                    //创建空表  
                    ITable pTable = pFWS.CreateTable("tempTable", fieldsEdit, null, null, "");
    
                    //获取DataTble中记录的数  
                    int count = mTable.Rows.Count;
                    //转换为ITable中的数据  
                    for (int i = 0; i < count; i++)
                    {
                        //在ITable中创建新纪录;获取DataTble中的记录
                        IRow row = pTable.CreateRow();
                        DataRow pRrow = mTable.Rows[i];
    
                        //列总数
                        int rowNum = pRrow.ItemArray.Length;
    
                        // 添加记录  
                        for ( int j = 1; j < rowNum ; j++)
                        {
                            row.set_Value(j, pRrow.ItemArray.GetValue(j));
                            row.Store();
                        }
                    }
                    return pTable;
                }
                catch (Exception ex)
                {
                    return null;
                }
            }            

    补充:在开发中发现,内存中的ITable无法作为参数传递给“连接字段”GP工具,会报错:传递的参数不是表。如果用IGPUtilities接口的MakeGPTableView方法生成IGPTableView再传递给“连接字段”GP工具时,会报错:Error 000732:数据集×××不存在或不被支持。

  • 相关阅读:
    Ubuntu安装后root 用户无法使用的解决方法
    struts2 上传 文件 注意问题
    WinSCP无法连接 ubuntu 的解决方法
    TOMCAT 6 中配置HTTPS
    Linux上安装ImageMagick和JMagick
    linux 下 Nginx 0.8.40的安装
    Displaying icons in a Flex List control
    Styling the Alert control’s message text
    Displaying icons in a Flex ComboBox control
    Styling the Alert control’s title bar
  • 原文地址:https://www.cnblogs.com/songqingguo/p/12629424.html
Copyright © 2020-2023  润新知