常用方法

一,获取Mxd地图文档的路径
/// <summary>
        /// 获取Mxd地图文档的路径
        /// </summary>
        /// <param name="MapControl"></param>
        private string OpenMxFile()
        {
            string mxdFile = "" ;
 
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = @"D:\Program Files (x86)\ArcGIS\DeveloperKit10.2\Samples\data";
            ofd.Filter = "Map Documents(*.Mxd)|*.mxd";
 
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                mxdFile = ofd.FileName;
 
            }
 
            return mxdFile;
        }


二,获取ShapeFile的路径
/// <summary>
        /// 获取ShapeFile的路径
        /// </summary>
        /// <returns></returns>
        private string[] OpenShapeFile()
        { 
          string[] ShpFile = new string[2];
          OpenFileDialog ofd = new OpenFileDialog();
          ofd.Title = "打开shp文件";
          ofd.InitialDirectory = @"D:\Program Files (x86)\ArcGIS\DeveloperKit10.2\Samples\data";
          ofd.Filter = "Shp文件(*.shp)|*.shp";
 
          if (ofd.ShowDialog()== System.Windows.Forms.DialogResult.OK)
          {
              string ShapePath = ofd.FileName;
              
              //利用"\\"将文件路径分成两部分
              int position = ShapePath.LastIndexOf("\\");
              string filePath = ShapePath.Substring(0,position);
              string fileName = ShapePath.Substring(position+1);
              ShpFile[0] = filePath;
              ShpFile[1] = fileName;
 
          }
 
          return ShpFile;
        }


posted @ 2016-09-09 10:16  FiberHomer  阅读(362)  评论(0编辑  收藏  举报