zoukankan      html  css  js  c++  java
  • ArcEngine开发——通过MapDocument组件类来访问maps和layers

    MapDocument是一个很有用的组件类,可用于读取和修改地图文档(.mxds)。本文演示如何打开一个地图文档,并且利用一个循环来访问其所有的地图(maps)和图层(layers)。在该示例中,将这些对象的名称输出到控制台。

    示例代码

    using System;
    using System.Collections.Generic;
    using System.Text;
    using ESRI.ArcGIS.Carto;
    using ESRI.ArcGIS.esriSystem;
    
    class Program
    {
        static void Main(string[] args)
        {
            OpenMXDViaMapDocument(@"F:\Test.mxd");
            Console.ReadKey();
        }
    
        static void OpenMXDViaMapDocument(string path)
        {
            IMapDocument pMapDocument = new MapDocumentClass();
            if (pMapDocument.get_IsMapDocument(path))
            {
                pMapDocument.Open(path, null);
                IMap pMap;
                for (int i = 0; i <= pMapDocument.MapCount - 1; i++)
                {
                    pMap = pMapDocument.get_Map(i);
                    Console.WriteLine(pMap.Name);
                    IEnumLayer pEnumLayer = pMap.get_Layers(null, true);
                    pEnumLayer.Reset();
                    ILayer pLayer = pEnumLayer.Next();
                    while (pLayer != null)
                    {
                        Console.WriteLine("--" + pLayer.Name);
    
                        pLayer = pEnumLayer.Next();
                    }
    
                }
            }
        }
    
    }

    地图文档组织结构

    演示程序输出

    另外,可以为get_Layers方法指定更为详细的参数,以获取符合条件的Layer。

    UID uid = new UID();
    uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";//这是获取IFeaureLayer,可以换其它的
    IEnumLayer pEnumLayer = axMapControl1.Map.get_Layers(uid, true);
    pEnumLayer.Reset();
    ILayer pLayer = pEnumLayer.Next();
    while (pLayer != null)
    {
           //...
    }
    

    具体的UID可用的其它类型如下:

  • 相关阅读:
    f12 接口自动刷新页面 来不及看接口信息 前端有没有传值
    order by 分组报错 shop 有三个字段 根据author 选出最大的price
    mybatis 动态sql
    正则 只有英文或者数字 长度6位以上 数字或者英文全部一样
    sql :1 :2
    前端Json数据,后台String接收,如何解析
    Json数据格式化
    LeetCode63. 不同路径 II
    LeetCode62. 不同路径
    LeetCode746. 使用最小花费爬楼梯
  • 原文地址:https://www.cnblogs.com/hans_gis/p/2030253.html
Copyright © 2011-2022 走看看