- 获取所有字段
//ITable iTable = ifc as ITable; //int fieldCount = iTable.Fields.FieldCount; int num = ifc.Fields.FieldCount;//字段的个数 for (int i = 0; i < num; i++) { string target = ifc.Fields.get_Field(i).AliasName; IField field = ifc.Fields.get_Field(i);//iTable.Fields.get_Field(i); if ((field.Type == esriFieldType.esriFieldTypeOID) || field.Type == esriFieldType.esriFieldTypeGeometry || field.Name.ToUpper() == "SHAPE_LENGTH" || field.Name.ToUpper() == "SHAPE_LENGTH()" || field.Name.ToUpper() == "SHAPE_AREA()" || field.Name.ToUpper() == "SHAPE_AREA" || field.Name.ToUpper() == "SHAPE.STAREA()" || field.Name.ToUpper() == "SHAPE.STLENGTH()") continue; else { string Name = ified.Name; string AliasName = ified.AliasName; esriFieldType Type = ified.Type; int Length = ified.Length; object DefaultValue = ified.DefaultValue; bool IsNullable = ified.IsNullable; int Precision = ified.Precision; int Scale = ified.Scale; } }
- 添加一个字段
IField addFied = new Field(); IFieldEdit editField = (IFieldEdit)addFied; editField.Name_2 = fieldName; //editField.AliasName_2 = ""; editField.Type_2 = esriFieldType.esriFieldTypeString;//esriFieldType.esriFieldTypeString editField.Length_2 = length; editField.Precision_2 = precision; editField.DefaultValue_2 = ""; editField.IsNullable_2 = true; ifc.AddField(addFied);
- 删除字段
int fieldIndex = m_feacls.Fields.FindField(name);//需要删除的字段名称 IField delField = iFields.get_Field(fieldIndex); ifc.DeleteField(delField);
- 添加多个字段
ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass(); ESRI.ArcGIS.Geodatabase.IFields fields = null; // if a fields collection is not passed in then supply our own if (fields == null) { // create the fields using the required fields method fields = objectClassDescription.RequiredFields; ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast ESRI.ArcGIS.Geodatabase.IField fieldBSM = new ESRI.ArcGIS.Geodatabase.FieldClass(); ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEditBSM = (ESRI.ArcGIS.Geodatabase.IFieldEdit)fieldBSM; // Explicit Cast fieldEditBSM.Name_2 = "BSM"; fieldEditBSM.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeInteger; fieldEditBSM.IsNullable_2 = true; fieldEditBSM.AliasName_2 = "标识码"; fieldEditBSM.Editable_2 = true; fieldsEdit.AddField(fieldBSM); ESRI.ArcGIS.Geodatabase.IField fieldYSDM = new ESRI.ArcGIS.Geodatabase.FieldClass(); ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEditYSDM = (ESRI.ArcGIS.Geodatabase.IFieldEdit)fieldYSDM; // Explicit Cast fieldEditYSDM.Name_2 = "YSDM"; fieldEditYSDM.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString; fieldEditYSDM.IsNullable_2 = true; fieldEditYSDM.AliasName_2 = "要素代码"; fieldEditYSDM.DefaultValue_2 = "0"; fieldEditYSDM.Editable_2 = true; fieldEditYSDM.Length_2 = 10; fieldsEdit.AddField(fieldYSDM); } ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace; fieldChecker.Validate(fields, out enumFieldError, out validatedFields);//检查字段的有效性,最终结果用validatedFields
- 添加一个字段
- 字段计算器
Geoprocessor gp = new Geoprocessor(); try { CalculateField c = new CalculateField(); c.in_table = m_ifc as ITable; c.field = name;//需要计算的字段名 c.expression = richTextBox1.Text;//"!shape.area!"或"!ZLDWDM!+!QSDWDM!"或"!JBNTMJ!"注意感叹号的运用 c.expression_type = "PYTHON"; gp.Execute(c, null); } catch { label7.Text = gp.GetMessage(3); MessageBox.Show(gp.GetMessage(3)); }
ArcEngine添加字段
最新推荐文章于 2021-01-29 14:27:50 发布