yycGIS

我们曾如此渴望命运的波澜,到最后才发现:人生最曼妙的风景,竟是内心的淡定与从容。 我们曾如此期盼外界的认可,到最后才知道:世界是自己的,与他人毫无关系。

Less is more, more is different!

导航

mapcontrol 遍历所有图层方法

通过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;
        }
 
 
 
获取其它类型的图层接口,同此类似。
 
 

posted on 2014-06-03 10:59  yycGIS  阅读(1378)  评论(0编辑  收藏  举报