Mapcontrol 遍歷全部圖層方法

mapcontrol 遍歷全部圖層方法
2011-04-29 19:51
經過IMap中的get_layers()能夠遍歷MapControl中當前的圖層。此方法能夠經過指定UID對圖層進行過濾或者分類。
 
1. 遍歷矢量圖層
 
 
  public IEnumLayer GetFeatureLayers()
        {
            UID uid = new UIDClass();
            uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";//FeatureLayer
            IEnumLayer layers = frmMap.m_mapCtrl.Map.get_Layers(uid, true);
            return layers;
        }
 
 
2. 遍歷柵格圖層
 
 
  public IEnumLayer GetRasterLayers()
        {
            UID uid = new UIDClass();
            uid.Value = "{D02371C7-35F7-11D2-B1F2-00C04F8EDEFF}";//RasterLayer
            IEnumLayer layers = frmMap.m_mapCtrl.Map.get_Layers(uid, true);
            return layers;
 }
 
 
3.遍歷其它圖層
 
只要修改相應的UID便可。常見的數據類型的UID有:
 
 
{6CA416B1-E160-11D2-9F4E-00C04F6BC78E} IDataLayer (包括全部類型的圖層)
{40A9E885-5533-11d0-98BE-00805F7CED21} IFeatureLayer
{E156D7E5-22AF-11D3-9F99-00C04F6BC78E} IGeoFeatureLayer
{34B2EF81-F4AC-11D1-A245-080009B6F22B} IGraphicsLayer
{5CEAE408-4C0A-437F-9DB3-054D83919850} IFDOGraphicsLayer
{0C22A4C7-DAFD-11D2-9F46-00C04F6BC78E} ICoverageAnnotationLayer
{EDAD6644-1810-11D1-86AE-0000F8751720} IGroupLayer
 
 
4. 經過圖層名獲取圖層接口
 
在AE開發中,這是經常使用到的功能,配合上面的方法,很容易實現。
 
 
 //獲取矢量圖層接口
 public IFeatureLayer GetFeatureLayer(string layerName)
        {
            //get the layers from the maps
            IEnumLayer layers = GetFeatureLayers();
            layers.Reset();
            ILayer layer = null;
 while ((layer = layers.Next()) != null)
            {
                if (layer.Name == layerName)
                    return layer as IFeatureLayer;
            }
            return null;
        }
 
//獲取柵格圖層接口        
public IRasterLayer GetRasterLayer(string layerName)
        {
            //get the layers from the maps
            IEnumLayer layers = GetRasterLayers();
            layers.Reset();
            ILayer layer = null;
            while ((layer = layers.Next()) != null)
            {
                if (layer.Name == layerName)
                    return layer as IRasterLayer;
            }
            return null;
        }
 
 
 
獲取其它類型的圖層接口,同此相似。
本篇文章來源於 3SDN  轉載請以連接形式註明出處 網址:http://www.3sdn.net/gis2dev/ae/2009-08-29/454.html
相關文章
相關標籤/搜索