- 删除字段
/// <summary> /// 删除字段 /// </summary> /// <param name="layer">目标要素类</param> /// <param name="fieldName">需要删除的字段</param> /// <returns></returns> static public bool DeleteField(IFeatureClass layer, string fieldName) { try { ITable pTable = (ITable)layer; IFields pfields; IField pfield; pfields = pTable.Fields; int fieldIndex = pfields.FindField(fieldName); pfield = pfields.get_Field(fieldIndex); pTable.DeleteField(pfield); return true; } catch (Exception ex) { return false; } }
2.添加字段
/// <summary> /// 添加字段 /// </summary> /// <param name="layer">目标要素类</param> /// <param name="fieldName">需要添加的字段</param> /// <param name="AliasName">需要添加的字段的别名</param> /// <param name="length">字段的长度</param> /// <returns></returns> static public bool AddField(IFeatureClass layer, string fieldName, string AliasName, int length) { try { ITable pTable = (ITable)layer; IFieldEdit pFieldEdit = new FieldClass() { IFieldEdit_Type_2 = esriFieldType.esriFieldTypeString, IFieldEdit_AliasName_2 = AliasName, IFieldEdit2_Name_2 = fieldName, IFieldEdit_Length_2 = 50, IFieldEdit_DefaultValue_2 = "-", IFieldEdit_IsNullable_2 = true }; pTable.AddField(pFieldEdit); return true; } catch (Exception ex) { return false; } }
3.编辑属性,像属性表中的行写入属性
static public void UpadateTable(IFeatureClass pFeatClass, List<FeatureCate> group1) { ITable pTable = pFeatClass as ITable; ICursor pCursor = pTable.Update(null, false); IRow pRow = pCursor.NextRow(); int indexOfBSM = pFeatClass.FindField("BSM"); int indexOfLZ_1 = pFeatClass.FindField("LZ"); int indexOfZYSZ_1 = pFeatClass.FindField("ZYSZ"); int indexOfZDGN_1 = pFeatClass.FindField("ZDGN"); if (indexOfBSM == -1 || indexOfLZ_1 == -1 || indexOfZYSZ_1 == -1) { MessageBox.Show("未找到字段"); } while (pRow != null) { string TableBSM = pRow.get_Value(indexOfBSM).ToString(); for (int i = 0; i < group1.Count; i++) { if (TableBSM == group1[i].BSM) { pRow.set_Value(indexOfLZ_1, group1[i].LZ_1); pRow.set_Value(indexOfZYSZ_1, group1[i].ZYSZ_1); pRow.set_Value(indexOfZDGN_1, group1[i].ZDGN_1); pCursor.UpdateRow(pRow); } } pRow = pCursor.NextRow(); } }