• 打开地图文件和shape文件代码加载Mxd文档


    代码加载Mxd文档

    用代码添加Mxd文档,用到AxMapControl.LoadMxFile(sFilePath),我们只要将Mxd文档的路径传给这个方法即可

    /// <summary>
            /// 打开地图文件
            /// </summary>
            /// <returns>文件的完整路径</returns>
            public string OpenMxd()
            {
                string MxdPath = "";
                OpenFileDialog OpenMXD = new OpenFileDialog();
                OpenMXD.Title = "打开地图";
                OpenMXD.InitialDirectory = "F:";
                OpenMXD.Filter = "地图文件(*.mxd)|*.mxd";
                if (OpenMXD.ShowDialog() == DialogResult.OK)
                {
                    MxdPath = OpenMXD.FileName;
                }
                return MxdPath;
            }
            /// <summary>
            /// 打开Shape文件,需要两个参数,shp文件所在目录,文件名
            /// </summary>
            /// <returns>数组,shp文件所在目录,文件名</returns>
            public string[] OpenShapeFile()
            {
                string[] ShpFile = new string[2];
                OpenFileDialog OpenShpFile = new OpenFileDialog();
                OpenShpFile.Title = "打开Shape文件";
                OpenShpFile.InitialDirectory = "F:";
                OpenShpFile.Filter = "Shape文件(*.shp)|*.shp";
                if (OpenShpFile.ShowDialog() == DialogResult.OK)
                {
                    string ShapPath = OpenShpFile.FileName;
                    //利用\将文件路径分为两部分
                    int Postion = ShapPath.LastIndexOf("\");
                    string FilePath = ShapPath.Substring(0, Postion);
                    string ShpName = ShapPath.Substring(Postion+1);
                    ShpFile[0] = FilePath;
                    ShpFile[1] = ShpName;
                }
                return ShpFile;
            }
            private void btnOpen_Click(object sender, EventArgs e)
            {
                //OpenFileDialog OpenMXD = new OpenFileDialog();
                //OpenMXD.Title = "打开地图";
                //OpenMXD.InitialDirectory = "F:";
                //OpenMXD.Filter = "地图文件(*.mxd)|*.mxd";
                //if (OpenMXD.ShowDialog() == DialogResult.OK)
                //{
                //    string MxdPath = OpenMXD.FileName;
                //    axMapControl1.LoadMxFile(MxdPath);
                //    //控件的LoadMXFIle是用来加载地图文档的。可以封装成函数OpenMxd()
                //}
               axMapControl1.LoadMxFile(OpenMxd());
                   
            }

  • 相关阅读:
    交换机模拟器
    bootstrap-分页-默认分页
    bootstrap-分页-默认分页
    bootstrap-分页-默认分页
    交易系统查询带上for update
    集成开发环境(IDE) Mix介绍
    Dapp及相关开发工具介绍
    区块链技术视频网站EthCast.com上线
    区块链:最小可行区块链原理解析1
    账户、交易核心概念及投注合约解析
  • 原文地址:https://www.cnblogs.com/qiushuixizhao/p/3234336.html
Copyright © 2020-2023  润新知