zoukankan      html  css  js  c++  java
  • ArcGIS Engine开发之地图基本操作(2)

    地图数据的加载

    1.加载地图文档

    ArcGIS Engine支持加载多种类型的数据,有矢量数据的Coverage、Shapefile、dwg/dxf文件,栅格数据的BMP、GRID、控件数据库等。很多情况下加载通过ArcGIS桌面制作的地图文档是最合适的(*.mxd格式)。

    加载地图的第三种方式:

    1. 使用IMAPControl接口的LoadMxfile方法加载。
    2. 通过IMAPDocument接口加载。
    3. 使用ArcGIS Engine中封装好的类库资源ControlsOpenDocCommandClass加载。

    1.使用IMAPControl接口的LoadMxFile方法加载地图文档

    思路如下:

    1. 通过.NET框架类提供的打开文件对话框选择要打开的地图文档。
    2. 用IMapControl接口提供的CheckMxFile方法检查是否为有效的地图数据,若有效则调用IMapControl接口提供的LoadMxfile方法进行加载。
      1. CheckMxFile方法:该方法的作用就是确定选中的地图文档是否是一个可以记载到MapControl控件中的有效地图文档。它能验证文件是否存在、文件的内部结构是否符合预期的存储格式。
      2. LoadMxFile方法:该方法的作用是想MapControl控件中加载地图文档,地图文档可以用索引或文件名指示。函数原型为public void LoadMxFile(string mxPath,object mapNameOrIndex,object password).
      3. 参数的说明表:
        参数 描述
        mxPath 选择,表示文件路径的字符串表达式
        mapNameOrIndex 可选,表示地图名或者索引号
        password 可选,表示密码

     

     

     

     

     代码:

     OpenFileDialog pOpenFileDialog = new OpenFileDialog();
                pOpenFileDialog.CheckFileExists = true;
                pOpenFileDialog.Title = "打开地图文档";
                pOpenFileDialog.Filter = "ArcMap文档(*.mxd)|*.mxd;|ArcMap模板(*.mxt)|.mxt|发布地图文件(*.pmf)|*pmf|所有地图格式(*.mxd;*.mxt;*.pmf)|*,mxd;*.mxt;*.pmf";
                pOpenFileDialog.Multiselect = false;//不允许多个文件同时选择
                pOpenFileDialog.RestoreDirectory = true;//存储打开的文件路径
                if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string pFileName = pOpenFileDialog.FileName;
                    if (pFileName == "")
                    {
                        return;
                    }
                    if (axMapControl1. CheckMxFile(pFileName))//检查地图文档是否有效
                    {
                       // ClearAllData();
                        axMapControl1. LoadMxFile(pFileName);
                    }
                    else
                    {
                        MessageBox.Show(pFileName + "是无效的地图文档!", "信息提示");
                        return;
                    }
                }

     2、通过IMapDocument接口加载地图文档

    IMapDocument接口定义了操作和管理地图文档对象的方法和属性。使用这个对象可以获取,更新一个文档的内容,设置文档文件的属性以及读写和保存一个文档文件等。IMapDocument接口同时扮演者数据显示和数据容器的双重身份,可以通过ActivieView获取Map数据视图。通过FocusMap属性获取当期那正在使用的Map对象的数据容器身份。一个文档可能有多个Map对象,但是在同一个时刻内,只能有一份Map处于使用状态。

    实例的代码:

    OpenFileDialog pOpenFileDialog = new OpenFileDialog();
                pOpenFileDialog.CheckFileExists = true;
                pOpenFileDialog.Title = "打开地图文档";
                pOpenFileDialog.Filter = "ArcMap文档(*.mxd)|*.mxd;|ArcGIS模板(*.mxt)|*.mxd|发布地图文件(*.pmf)|*.pmf|所有的地图格式(*.mxd;*.mxt;*.pmf)|*.mxd;*.mxt;*.pmf";
                pOpenFileDialog.Multiselect = false;
                pOpenFileDialog.RestoreDirectory = true;
                if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string pFileName = pOpenFileDialog.FileName;
                    if (pFilreName == "")
                    {
                        return;
                    }
                    if (MapControl1.checkMxFiile(pFileName))//检查地图文档有效性
                    {
                        //将数据在载入pMapDocument并与Map控件关联
                        //using Esri.ArcGIS .Carto 
                        IMapDocument pMapDocument = new MapDocument();
                        pMapDocument.Open(pFileName);
                        //获取Map中激活的地图文档
                        mainMapControl.Map = pMapDocument.ActiveView.FocusMap;
                        mainMapControl.ActiveView.Refresh();
                    }
                    else
                    {
                        MessageBox(pFileName + "是无效的地图文档!", "信息提示");
                        return;
                    }
                }

    3、使用ControlOpenDocCommandClass加载地图

    使用ArcGIS Engine中封装好的类库资源ControlsOpenDocCommandClass实现地图文档的加载,核心的代码:

     ICommand command = new ControlsOpenDocCommandClass();
                command.OnCreate(mainMapControl.Object);
                command.OnClick();

     

  • 相关阅读:
    Digital Video Stabilization and Rolling Shutter Correction using Gyroscope 论文笔记
    Distortion-Free Wide-Angle Portraits on Camera Phones 论文笔记
    Panorama Stitching on Mobile
    Natural Image Stitching with the Global Similarity Prior 论文笔记 (三)
    Natural Image Stitching with the Global Similarity Prior 论文笔记(二)
    Natural Image Stitching with the Global Similarity Prior 论文笔记(一)
    ADCensus Stereo Matching 笔记
    Efficient Large-Scale Stereo Matching论文解析
    Setting up caffe on Ubuntu
    Kubernetes配置Secret访问Harbor私有镜像仓库
  • 原文地址:https://www.cnblogs.com/dongteng/p/5869793.html
Copyright © 2011-2022 走看看