1、加載地圖文檔
在ArcGIS中,以mxd作為擴展名的文件叫地圖文檔。
地圖文檔中只是包含圖層的引用,即存儲當前地圖的圖層路徑、符號、狀態、修飾等信息,並不存儲真實的數據層。
ArcGIS Map中,圖層(Layer)是地圖(Map)的基本組成單位。圖層可以是要素圖層,也可以是柵格圖層。要素圖層有點、線、面3種顯示不同類型要素類的圖層,也有專題圖層,如顯示拓撲檢查結果的圖層、網絡分析結果圖層等;柵格圖層是航片、遙感影像、數字高程模型、普通圖片等。
介紹兩種打開mxd文件的方法
方法一:運用LoadMxFile方法的函數參數加載地圖文檔
地圖文檔的加載功能將用到MapControl控件提供的LoadMxFile方法。
//三個參數(filePath——文件路徑、0——地址名稱或索引、Type.Missing——通過反射進行調用獲取參數的默認值) axMapControl1.LoadMxFile(filePath, 0, Type.Missing);
該方法通過指定的*.mxd文檔路徑直接獲取。
該方法第一個參數是文件的路徑,第二個參數是mxd文檔中地圖的名稱或者索引,第三個參數是打開地圖文檔的密碼。
方法二:運用MapDocument對象中的Open方法的函數加載mxd文檔
//filePath——地圖文檔的路徑, ""——賦予默認密碼 mapDocument.Open(filePath, "");
通過MapDocument對象對地圖文檔的地圖逐個加載,MapDocument提供了Open方法,用於打開一個地圖文檔文
件,該方法的第一個參數為地圖文檔文件的路徑,第二個參數為密碼。
核心代碼:
#region 加載mxd地圖文檔 private void 加載mxd地圖文檔toolStripLabel1_Click(object sender, EventArgs e) { //方法一: //loadMapDoc1();//調用MapControl控件的LoadMxFile方法 //方法二: loadMapDoc2(); } /// <summary> /// 方法二:運用MapDocument對象中的Open方法的函數加載mxd文檔 /// </summary> private void loadMapDoc2() { IMapDocument mapDocument = new MapDocumentClass(); try { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "打開地圖文檔"; ofd.Filter = "map documents(*.mxd)|*.mxd"; if(ofd.ShowDialog()==DialogResult.OK) { string pFileName = ofd.FileName; //filePath——地圖文檔的路徑, ""——賦予默認密碼 mapDocument.Open(pFileName, ""); for (int i = 0; i < mapDocument.MapCount; i++) { //通過get_Map(i)方法逐個加載 axMapControl1.Map = mapDocument.get_Map(i); } axMapControl1.Refresh(); } else { mapDocument = null; } } catch(Exception e) { MessageBox.Show(e.ToString()); } } /// <summary> /// 方法一:運用LoadMxFile方法的函數參數加載地圖文檔 /// </summary> private void loadMapAccDoc1() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "打開地圖文檔"; ofd.Filter = "map documents(*.mxd)|*.mxd"; ofd.InitialDirectory = m_Path; //判斷, 如果對話框結構不為OK, 退出函數體 DialogResult DR = ofd.ShowDialog(); if (DR != DialogResult.OK) return; string filePath = ofd.FileName; if (axMapControl1.CheckMxFile(filePath)) { //設置axMapControl控制鼠標指針圖標選項為沙漏光標 axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerArrowHourglass; //三個參數(filePath——文件路徑、0——地址名稱或索引、Type.Missing——通過反射進行調用獲取參數的默認值) axMapControl1.LoadMxFile(filePath, 0, Type.Missing); //定義axMapControl控制鼠標指針圖標為默認箭頭 axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault; axMapControl1.Extent = axMapControl1.FullExtent; } else { MessageBox.Show(filePath + "不是有效的地圖文檔"); } } #endregion
謝謝觀看!本人初學GIS二次開發,如果有不對的地方,請多多包涵!
