以前用过这个类做字段计算,许久不用有些忘却,记录一下使用方式
public static void CalculateField(IFeatureLayer featureLayer,IField field,string expression)
{
Geoprocessor gp = new Geoprocessor { OverwriteOutput = true };
CalculateField cal = new CalculateField()
{
in_table = featureLayer,
field = field.Name,
expression = expression,
expression_type = "PYTHON_9.3"
};
gp.Execute(cal, null);
}
调用时,如果expression为"",即空,需要这样使用:"\"\""
例
CalculateField(pFeatureLayer,pFeatureLayer.FeatureClass.Fields.get_Field( pFeatureLayer.FeatureClass.FindField( item.SubItems[1].Text)), "\"\"");