标签:
在mxd中,一般图层的名称与其真实的
shp或影像文件名称不相同(注记图层一般放在mdb或gdb中,其在mxd中显示时的名称与其本身一样,直接使用lyr.name即可),使用ILayer的name属性,只能获取此图层在mxd中的别名,获取文件名称,需要将图层先转换成IDataLayer,将此对象的DatasourceName属性
转换成IDatasetName类型,然后获取IDatasetName的Name属性,此即为图层的真实文件名称。
一、所有图层适用
ArrayList listName = new ArrayList(); ArrayList listAlias = new ArrayList(); string layerName = ""; string layerAliasName=""; for (int i = 0; i < mapcontrol.LayerCount; i++) { ILayer layer = mapcontrol.get_Layer(i); layerName = layer.Name; layerAliasName = layer.Name; IDataLayer2 pFd = layer as IDataLayer2; if (pFd != null) { if (pFd.DataSourceName is IDatasetName) { //获取原始名称 IDatasetName pDN = pFd.DataSourceName as IDatasetName; layerAliasName = pDN.Name; } } listName.Add(layerName); listAlias.Add(layerAliasName); }
二、如果仅仅是矢量图层的话
ILayer pLayer = m_Map.get_Layer(i); //从map中取到一个ILayer对象 IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; //强转为IFeatureLayer对象 string layerName = pFeatureLayer.FeatureClass.AliasName; //获取别名
参照:
http://www.cnblogs.com/feilong3540717/archive/2011/08/24/2151790.html
http://blog.csdn.net/muzai/article/details/5807266
标签:
原文地址:http://www.cnblogs.com/GISRSMAN/p/4570542.html