码迷,mamicode.com
首页 > 数据库 > 详细

Geodatabase - 修改字段别名(Field Alias)

时间:2014-10-29 14:41:01      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   ar   sp   数据   div   

  以下代码演示的是通过个人数据库打开要素类,并对指定的字段别名进行修改,其中,需要注意的是,不能通过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)

标签:des   style   blog   io   color   ar   sp   数据   div   

原文地址:http://www.cnblogs.com/listened/p/4059299.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!