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

  • 相关阅读:
    iOS 苹果开发证书失效的解决方案(Failed to locate or generate matching signing assets)
    iOS NSArray数组过滤
    App Store2016年最新审核规则
    iOS 根据字符串数目,自定义Label等控件的高度
    iOS 证书Bug The identity used to sign the executable is no longer valid 解决方案
    Entity FrameWork 增删查改的本质
    EF容器---代理类对象
    Entity FrameWork 延迟加载本质(二)
    Entity FrameWork 延迟加载的本质(一)
    Entity FrameWork 增删查改
  • 原文地址:https://www.cnblogs.com/atravellers/p/1646236.html
Copyright © 2011-2022 走看看