




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、AE開發(fā)之基于幾何網(wǎng)絡(luò)的最短路徑分析1、實習目的本次實習目的在于熟練掌握ArcGIS Engine開發(fā)工具并能夠通過C#語言在VS 2010開發(fā)環(huán)境中完成查詢幾何網(wǎng)絡(luò)的最短路徑分析的功能。2、實習時間2015年5月23日星期六3、實習內(nèi)容3.1實驗環(huán)境操作系統(tǒng):Windows 2007二次開發(fā)平臺:VS 2010開發(fā)環(huán)境、ArcGIS Desktop10.0、AE開發(fā)組件3.2實驗任務(wù)完成基于幾何網(wǎng)絡(luò)分析的最短路徑查詢功能,即實現(xiàn)通過在幾何網(wǎng)絡(luò)地圖中指定起始點,能夠查詢經(jīng)過起始點的最短路線,并能夠通過縮放功能在地圖窗口居中顯示。3.3實驗步驟3.3.1新建項目選擇文件新建項目,如圖選擇項目類型
2、中Visual C#,再選擇Windows Application,記為“FindShortPath”,點擊確定。3.3.2添加控件3.3.3控件綁定因為添加的控件只是單獨存在,但是程序需要各控件間協(xié)同工作,因此要進行控件綁定。3.3.4創(chuàng)建幾何網(wǎng)絡(luò)1.在ArcCataLog中新建個人地理數(shù)據(jù)庫“甘地的個人地理數(shù)據(jù)庫”,然后新建要素數(shù)據(jù)集“road”,接著,鼠標右鍵選擇要素數(shù)據(jù)集“road”,選擇“導入要素類”,導入需要創(chuàng)建幾何網(wǎng)絡(luò)的要素類“主要公路”,輸出要素類的名字改為“road”,如下圖所示:2.鼠標右鍵選擇要素數(shù)據(jù)集“road”,選擇新建“幾何網(wǎng)絡(luò)”,則出現(xiàn)“新建幾何網(wǎng)絡(luò)”對話框,作如
3、下圖所示的一系列設(shè)置,最終得到幾何網(wǎng)絡(luò)“road_Net”。 至此,得到幾何網(wǎng)絡(luò)“road_Net”,如下圖所示:3.3.5代碼實現(xiàn)最短路徑分析1 設(shè)置ToolStrip12 添加代碼private IActiveView m_ipActiveView; private IMap m_ipMap;/地圖控件中地圖 private IGraphicsContainer pGC;/圖形對象 private bool clicked = false; int clickedcount = 0; private double m_dblPathCost = 0; private IGeometricN
4、etwork m_ipGeometricNetwork; private IPointCollection m_ipPoints;/輸入點集合 private IPointToEID m_ipPointToEID; private IEnumNetEID m_ipEnumNetEID_Junctions; private IEnumNetEID m_ipEnumNetEID_Edges; private IPolyline m_ipPolyline; private IMapControl3 mapctrlMainMap = null;private void Form1_Load(objec
5、t sender, EventArgs e) /對象初始化 mapctrlMainMap = (IMapControl3)this.axMapControl1.Object; m_ipActiveView = axMapControl1.ActiveView; m_ipMap = m_ipActiveView.FocusMap; clicked = false; pGC = m_ipMap as IGraphicsContainer; private void Findpath_Click(object sender, EventArgs e) mapctrlMainMap.CurrentTo
6、ol = null; /設(shè)置鼠標樣式 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; if (axMapControl1.LayerCount = 0) MessageBox.Show("請先加載幾何網(wǎng)絡(luò)數(shù)據(jù)!"); return; m_ipActiveView = axMapControl1.ActiveView; m_ipMap = m_ipActiveView.FocusMap; clicked = false; pGC = m_ipMap as IGraphics
7、Container; ILayer ipLayer = m_ipMap.get_Layer(0); IFeatureLayer ipFeatureLayer = ipLayer as IFeatureLayer; IFeatureDataset ipFDS = ipFeatureLayer.FeatureClass.FeatureDataset; OpenFeatureDatasetNetwork(ipFDS); clicked = true; clickedcount = 0; pGC.DeleteAllElements(); private void SolvePath_Click(obj
8、ect sender, EventArgs e) axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; if (SolvePathGan("Weight")/先解析路徑 IPolyline ipPolyResult = PathPolyLine();/最后返回最短路徑 clicked = false; if (ipPolyResult.IsEmpty) MessageBox.Show("沒有路徑可到!"); else IRgbColor color = new
9、RgbColorClass(); color.Red = 255; color.Blue = 64; color.Green = 128; LineElementClass element = new LineElementClass(); ILineSymbol linesymbol = new SimpleLineSymbolClass(); linesymbol.Color = color as IColor; linesymbol.Width = 3; element.Geometry = m_ipPolyline; element.Symbol = linesymbol; pGC.A
10、ddElement(element, 0); m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); axMapControl1.FlashShape(element.Geometry); MessageBox.Show("路徑經(jīng)過" + m_ipEnumNetEID_Edges.Count + "條線" + "rn" + "經(jīng)過節(jié)點數(shù)為" + m_ipEnumNetEID_Junctions.Count + &q
11、uot;rn" + "路線長度為" + m_ipPolyline.Length.ToString("#.#") + "rn", "幾何路徑信息"); /路徑縮放功能 private void SuoFang_Click(object sender, EventArgs e) if (m_ipPolyline = null) MessageBox.Show("當前沒有執(zhí)行路徑查詢!請確認!"); else this.axMapControl1.Extent = m_ipPolyline.
12、Envelope; #region 自定義路徑查詢函數(shù) public void OpenFeatureDatasetNetwork(IFeatureDataset FeatureDataset) CloseWorkspace(); if (!InitializeNetworkAndMap(FeatureDataset) Console.WriteLine("打開network出錯"); /關(guān)閉工作空間 private void CloseWorkspace() m_ipGeometricNetwork = null; m_ipPoints = null; m_ipPoint
13、ToEID = null; m_ipEnumNetEID_Junctions = null; m_ipEnumNetEID_Edges = null; m_ipPolyline = null; /初始化幾何網(wǎng)絡(luò)和地圖 private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset) IFeatureClassContainer ipFeatureClassContainer; IFeatureClass ipFeatureClass; IGeoDataset ipGeoDataset; ILayer ipLayer; IF
14、eatureLayer ipFeatureLayer; IEnvelope ipEnvelope, ipMaxEnvelope; double dblSearchTol; INetworkCollection ipNetworkCollection = FeatureDataset as INetworkCollection; int count = ipNetworkCollection.GeometricNetworkCount; /獲取第一個幾何網(wǎng)絡(luò)工作空間 m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0
15、); INetwork ipNetwork = m_ipGeometricNetwork.Network; if (m_ipMap != null) ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer; count = ipFeatureClassContainer.ClassCount; for (int i = 0; i < count; i+) ipFeatureClass = ipFeatureClassContainer.get_Class(i); ipFeatureLayer = n
16、ew FeatureLayerClass(); ipFeatureLayer.FeatureClass = ipFeatureClass; for (int j = 0; j < m_ipMap.LayerCount; j+) if (m_ipMap.get_Layer(j).Name.ToUpper() = ipFeatureLayer.Name.ToUpper() continue; count = m_ipMap.LayerCount; ipMaxEnvelope = new EnvelopeClass(); for (int i = 0; i < count; i+) ip
17、Layer = m_ipMap.get_Layer(i); ipFeatureLayer = ipLayer as IFeatureLayer; ipGeoDataset = ipFeatureLayer as IGeoDataset; ipEnvelope = ipGeoDataset.Extent; ipMaxEnvelope.Union(ipEnvelope); m_ipPointToEID = new PointToEIDClass(); m_ipPointToEID.SourceMap = m_ipMap; m_ipPointToEID.GeometricNetwork = m_ip
18、GeometricNetwork; double dblWidth = ipMaxEnvelope.Width; double dblHeight = ipMaxEnvelope.Height; if (dblWidth > dblHeight) dblSearchTol = dblWidth / 100; else dblSearchTol = dblHeight / 100; m_ipPointToEID.SnapTolerance = dblSearchTol; return true; /返回路徑的幾何體 public IPolyline PathPolyLine() IEIDI
19、nfo ipEIDInfo; IGeometry ipGeometry; if (m_ipPolyline != null) return m_ipPolyline; m_ipPolyline = new PolylineClass(); IGeometryCollection ipNewGeometryColl = m_ipPolyline as IGeometryCollection;/引用傳遞 ISpatialReference ipSpatialReference = m_ipMap.SpatialReference; IEIDHelper ipEIDHelper = new EIDH
20、elper(); ipEIDHelper.GeometricNetwork = m_ipGeometricNetwork; ipEIDHelper.OutputSpatialReference = ipSpatialReference; ipEIDHelper.ReturnGeometries = true; IEnumEIDInfo ipEnumEIDInfo = ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges); int count = ipEnumEIDInfo.Count; ipEnumEIDInfo.Reset(); for (i
21、nt i = 0; i < count; i+) string info; info = new stringcount; ipEIDInfo = ipEnumEIDInfo.Next(); ipGeometry = ipEIDInfo.Geometry; ipNewGeometryColl.AddGeometryCollection(ipGeometry as IGeometryCollection); infoi = m_ipPolyline.Length.ToString(); return m_ipPolyline; public bool SolvePathGan(string
22、 WeightName) try int intJunctionUserClassID; int intJunctionUserID; int intJunctionUserSubID; int intJunctionID; IPoint ipFoundJunctionPoint; ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolver() as ITraceFlowSolverGEN; INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver; if (m_ipGeomet
23、ricNetwork = null) return false; INetwork ipNetwork = m_ipGeometricNetwork.Network; ipNetSolver.SourceNetwork = ipNetwork; INetElements ipNetElements = ipNetwork as INetElements; if (m_ipPoints = null) MessageBox.Show("請選擇點!"); return false; int intCount = m_ipPoints.PointCount;/這里的points有
24、值嗎? /定義一個邊線旗數(shù)組 /*最近點*/ IJunctionFlag pJunctionFlagList = new JunctionFlagintCount; for (int i = 0; i < intCount; i+) INetFlag ipNetFlag = new JunctionFlag() as INetFlag; IPoint ipJunctionPoint = m_ipPoints.get_Point(i); /查找輸入點的最近的網(wǎng)絡(luò)點 m_ipPointToEID.GetNearestJunction(ipJunctionPoint, out intJunct
25、ionID, out ipFoundJunctionPoint); ipNetElements.QueryIDs(intJunctionID, esriElementType.esriETJunction, out intJunctionUserClassID, out intJunctionUserID, out intJunctionUserSubID); ipNetFlag.UserClassID = intJunctionUserClassID; ipNetFlag.UserID = intJunctionUserID; ipNetFlag.UserSubID = intJunctio
26、nUserSubID; IJunctionFlag pTemp = (IJunctionFlag)(ipNetFlag as IJunctionFlag); pJunctionFlagListi = pTemp; ipTraceFlowSolver.PutJunctionOrigins(ref pJunctionFlagList); INetSchema ipNetSchema = ipNetwork as INetSchema; INetWeight ipNetWeight = ipNetSchema.get_WeightByName(WeightName); INetSolverWeigh
27、ts ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights; ipNetSolverWeights.FromToEdgeWeight = ipNetWeight;/開始邊線的權(quán)重 ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight;/終止邊線的權(quán)重 object vaRes = new objectintCount - 1; /通過findpath得到邊線和交匯點的集合 ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnecte
28、d, esriShortestPathObjFn.esriSPObjFnMinSum,out m_ipEnumNetEID_Junctions, out m_ipEnumNetEID_Edges, intCount - 1, ref vaRes); m_dblPathCost = 0; for (int i = 0; i < vaRes.Length; i+) double m_Va = (double)vaResi; m_dblPathCost = m_dblPathCost + m_Va; m_ipPolyline = null; return true; catch (Exception ex) Console.WriteLine(ex.Message); return false; #endregion private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) if (clicked != true) return; IPoint ipNew; if (m_ipPoints = null) m_ipPoin
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 8人之初(教學設(shè)計)-2023-2024學年語文一年級下冊統(tǒng)編版
- 12己亥雜詩教學設(shè)計-2024-2025學年五年級上冊語文統(tǒng)編版
- 10《在牛肚子里的旅行》教學設(shè)計-2024-2025學年語文三年級上冊統(tǒng)編版
- 7 《敬業(yè)與樂業(yè)》教學設(shè)計2024-2025學年九年級上冊語文同步備課(統(tǒng)編版)
- 2024-2025學年高中歷史 第五單元 近代中國的思想解放潮流 第14課 從“師夷長技”到維新變法新課教學實錄2 新人教版必修3
- 6我家的好鄰居 (教學設(shè)計)-部編版道德與法治三年級下冊
- 2024年四年級品德與社會上冊 第二單元 做健康文明生活的小主人 第7課《我有自己的好主意》教學實錄 粵教版
- 5 認識棱鏡 教學設(shè)計-2024-2025學年科學五年級上冊教科版
- 2024-2025學年高中歷史 第七單元 無產(chǎn)階級和人民群眾爭取民主的斗爭 第4課 抗戰(zhàn)勝利后的人民民主運動教學實錄 新人教版選修2
- 6《散步》教學設(shè)計-2024-2025學年統(tǒng)編版語文七年級上冊(2024)001
- 2024版非ST段抬高型急性冠脈綜合征診斷和治療指南解讀
- 銀行網(wǎng)點裝修工程施工組織設(shè)計方案
- 2025初級會計理論考試100題及解析
- 中華人民共和國統(tǒng)計法
- 《 大學生軍事理論教程》全套教學課件
- 中考數(shù)學計算題練習100道(2024年中考真題)
- 業(yè)主授權(quán)租戶安裝充電樁委托書
- 2023公務(wù)員年度考核表個人總結(jié)600字
- 氣質(zhì)類型測試量表
- 話單類型解析
- 趣味運動會方案1
評論
0/150
提交評論