首页 > 代码库 > Geodatabase - 修改字段别名(Field Alias)
Geodatabase - 修改字段别名(Field Alias)
以下代码演示的是通过个人数据库打开要素类,并对指定的字段别名进行修改,其中,需要注意的是,不能通过Engine中的AxMapControl直接获得,如
1 //直接获得IFeatureClass.2 //ESRI.ArcGIS.Carto.ILayer lyr = mapCtrl_main.get_Layer(0);3 //ESRI.ArcGIS.Carto.IFeatureLayer flyr = (ESRI.ArcGIS.Carto.IFeatureLayer)lyr;4 //ESRI.ArcGIS.Geodatabase.IFeatureClass fc = flyr.FeatureClass;
这样是不可以的:
1 /// <summary> 2 /// 修改字段别名. 3 /// </summary> 4 /// <param name="personalWorkspacePath">个人数据库路径(当然可以为其他类型数据库),如"G:\doc\gis\1.400\data\pdb.mdb"</param> 5 /// <param name="featureClassName">要素类名,如"hyd1_4l_1"</param> 6 /// <param name="oriFieldName">原字段别名,如"FNODE_".</param> 7 /// <param name="desFieldName">新字段别名,如"fnode".</param> 8 private void AlterFieldAliasName(string personalWorkspacePath, string featureClassName, string oriFieldName, string desFieldName) { 9 //通过IFeatureWorkspace获得IFeatureClass.10 ESRI.ArcGIS.Geodatabase.IWorkspaceFactory wsf = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();11 ESRI.ArcGIS.Geodatabase.IWorkspace ws = wsf.OpenFromFile(personalWorkspacePath, 0);12 ESRI.ArcGIS.Geodatabase.IFeatureWorkspace fws = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)ws;13 ESRI.ArcGIS.Geodatabase.IFeatureClass fc = fws.OpenFeatureClass(featureClassName);14 15 ESRI.ArcGIS.Geodatabase.ITable t = (ESRI.ArcGIS.Geodatabase.ITable)fc;16 if (t.FindField(oriFieldName) == -1) //无指定字段名.17 return;18 19 ESRI.ArcGIS.Geodatabase.IObjectClass objClass = (ESRI.ArcGIS.Geodatabase.IObjectClass)fc;20 ESRI.ArcGIS.Geodatabase.ISchemaLock slock = (ESRI.ArcGIS.Geodatabase.ISchemaLock)objClass;21 try {22 slock.ChangeSchemaLock(ESRI.ArcGIS.Geodatabase.esriSchemaLock.esriExclusiveSchemaLock);23 ESRI.ArcGIS.Geodatabase.IClassSchemaEdit cSchemaEdit = (ESRI.ArcGIS.Geodatabase.IClassSchemaEdit)t;24 cSchemaEdit.AlterFieldAliasName(oriFieldName, desFieldName);25 MessageBox.Show("done");26 }27 catch (System.Exception ex) {28 MessageBox.Show(ex.Message);29 }30 finally {31 if (slock != null)32 slock.ChangeSchemaLock(ESRI.ArcGIS.Geodatabase.esriSchemaLock.esriSharedSchemaLock);33 }34 }
Geodatabase - 修改字段别名(Field Alias)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。