以下代码演示的是通过个人数据库打开要素类,并对指定的字段别名进行修改,其中,需要注意的是,不能通过Engine中的AxMapControl直接获得,如

  //直接获得IFeatureClass.
//ESRI.ArcGIS.Carto.ILayer lyr = mapCtrl_main.get_Layer(0);
//ESRI.ArcGIS.Carto.IFeatureLayer flyr = (ESRI.ArcGIS.Carto.IFeatureLayer)lyr;
//ESRI.ArcGIS.Geodatabase.IFeatureClass fc = flyr.FeatureClass;

  这样是不可以的:

 /// <summary>
/// 修改字段别名.
/// </summary>
/// <param name="personalWorkspacePath">个人数据库路径(当然可以为其他类型数据库),如"G:\doc\gis\1.400\data\pdb.mdb"</param>
/// <param name="featureClassName">要素类名,如"hyd1_4l_1"</param>
/// <param name="oriFieldName">原字段别名,如"FNODE_".</param>
/// <param name="desFieldName">新字段别名,如"fnode".</param>
private void AlterFieldAliasName(string personalWorkspacePath, string featureClassName, string oriFieldName, string desFieldName) {
//通过IFeatureWorkspace获得IFeatureClass.
ESRI.ArcGIS.Geodatabase.IWorkspaceFactory wsf = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspace ws = wsf.OpenFromFile(personalWorkspacePath, );
ESRI.ArcGIS.Geodatabase.IFeatureWorkspace fws = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)ws;
ESRI.ArcGIS.Geodatabase.IFeatureClass fc = fws.OpenFeatureClass(featureClassName); ESRI.ArcGIS.Geodatabase.ITable t = (ESRI.ArcGIS.Geodatabase.ITable)fc;
if (t.FindField(oriFieldName) == -) //无指定字段名.
return; ESRI.ArcGIS.Geodatabase.IObjectClass objClass = (ESRI.ArcGIS.Geodatabase.IObjectClass)fc;
ESRI.ArcGIS.Geodatabase.ISchemaLock slock = (ESRI.ArcGIS.Geodatabase.ISchemaLock)objClass;
try {
slock.ChangeSchemaLock(ESRI.ArcGIS.Geodatabase.esriSchemaLock.esriExclusiveSchemaLock);
ESRI.ArcGIS.Geodatabase.IClassSchemaEdit cSchemaEdit = (ESRI.ArcGIS.Geodatabase.IClassSchemaEdit)t;
cSchemaEdit.AlterFieldAliasName(oriFieldName, desFieldName);
MessageBox.Show("done");
}
catch (System.Exception ex) {
MessageBox.Show(ex.Message);
}
finally {
if (slock != null)
slock.ChangeSchemaLock(ESRI.ArcGIS.Geodatabase.esriSchemaLock.esriSharedSchemaLock);
}
}
05-08 15:32