向已存在的要素类中添加字段

在写AE程序的时候,一定要进行License的验证。如果是WinForm程序,可以向窗口上拖放一个ArcGIS License控件;如果是Console程序,可以添加ArcGIS License Checking代码

1)通过IFieldsEdit接口的AddField方法的函数

static void AddField_IFields(IFeatureClass pFC, string name)
{
IFields pFields = pFC.Fields;
IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = name;
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
pFieldsEdit.AddField(pField);
}
2)通过IClass接口的AddField方法的函数
static void AddField_IClass(IFeatureClass pFc, string name)
{
IFields pFields = pFc.Fields;
IClass pClass = pFc as IClass;
IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = name;
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
pClass.AddField(pField);

}

向已存在的FeatureClass中添加新字段,需要使用IClass接口的AddField方法,而如果使用IFieldsEdit接口的AddField方法并不能成功的添加。

转载自:https://blog.csdn.net/foreverling/article/details/36396745

You may also like...