zoukankan      html  css  js  c++  java
  • ArcEngine中对已经存在的数据表格添加字段(转载)

    下例中是对mapControl中当前地图添加“name_city”字段,主要用到IField,IFieldEdit,ITable(IClass),IFeatureLayer,IFeatureClass,IFeature字段,其中IField,IFieldEdit是创建新的字段“name_city”,每个要素的“name_city”字段存储的都是“city_name”。

    注意:在调用AddField方法时,利用ITable或者IClass,而不能使用IFieldsEdit,参考AE的帮助文档:

    The IFieldsEdit interface is used when creating a fields collection. You cannot use it to insert or delete a field from a fields collection belonging to an existing table. To add a field to an existing object class, use the IClass::AddField method.  To remove a field from an existing object class, use the IClass::DeleteField method.

    从上面,我们知道IFieldsEdit 在创建新的数据表格时起作用,而要插入或者删除当前已经存在的数据表时,利用IClass。ITable继承于IClass,因此也可以使用ITable。

    view plaincopy to clipboardprint?
    //new a field and add to the first layer in the map  
                //new a field: "name_cit", type:string  
                IField pField = new FieldClass();  
                IFieldEdit pFieldEdit = pField as IFieldEdit;  
                pFieldEdit.Name_2 = "name_city";  
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;  
                //achieve the first layer in the map  
                IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;  
                IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;  
                IClass pTable = pFeatureClass as IClass;        //use ITable or IClass  
                pTable.AddField(pFieldEdit);  
                //set values of every feature's field-"name_cit" in the first layer  
                for (int i = 0; i < pFeatureClass.FeatureCount(null); i++)  
                {  
                    IFeature pFeature = pFeatureClass.GetFeature(i);  
                    pFeature.set_Value(pFeature.Fields.FindField("name_city"), "city_name");  
                    pFeature.Store();  
                } 


    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jingss_3/archive/2010/01/04/5127951.aspx

  • 相关阅读:
    第九届蓝桥杯JavaA组省赛真题
    Qt的IDE开发环境(KDevelop,MonKey Studio,QDevlop,Dev-cpp,Cobras,Edyuk)
    Eclipse+Qt开发环境设置(Linux和Win)
    Visual Studio 2005安装qt-win-commercial-src-4.3.1,并设置环境变量
    在VC6.0中编译头文件时产生moc文件
    Qt配置信息设置(QSettings在不同平台下的使用路径)
    应对业务需求变化?
    开发环境准备:Ruby on Rails开发环境配置
    VS2013中Python学习环境搭建
    JQUERY 插件开发——MENU(导航菜单)
  • 原文地址:https://www.cnblogs.com/atravellers/p/1646236.html
Copyright © 2011-2022 走看看