




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、ArcGIS Server 9.3 最短路徑分析要做網(wǎng)絡分析,首先你的arcgis server需要具有network analysis 擴展模塊的license。其次需要網(wǎng)絡數(shù)據(jù)集,這個問題好解決,直接使用安裝目錄下的ArcGIS"DeveloperKit"SamplesNET"Server"data"SanFrancisco下的網(wǎng)絡數(shù)據(jù)集將其發(fā)布,發(fā)布時記得勾上NetWork Anaysis 這項。然后新建一個網(wǎng)站,加上常用的map,mapresourcemanager,toolbar,toc 控件等,在mapresourcemanager
2、中加入兩個資源,一個是graphicslayer類型,命名為 pathLayer,一個為ArcGIS Server Local類型,命名為SanFrancisco,并加上兩個textbox和一個按鈕,布置好后如圖1。首先在前臺的代碼如下:/函數(shù)search()即為所加按鈕的onclick對應的函數(shù)。<script type="text/javascript"> function search()
3、 /起點的名稱 var v1=document.getElementById("Text1").value; /終點的名稱 var v2=document.getElementById("Text2").value; var argum
4、ent = "ControlID=Map1&ControlType=Map&Type=findPath&p1="+v1+"&p2="+v2; var context = "Map" <%= m_Callback %> &
5、#160; function processCallbackError() alert(66); </script> 后臺還是callback機制來實現(xiàn)的。代碼如下:public partial class _Default : System.Web.UI.Page,ICallbackEventHandler public string m_C
6、allback = String.Empty; public string smapstring = String.Empty; protected void Page_Load(object sender, EventArgs e) if (!IsPostBack) m_
7、Callback = Page.ClientScript.GetCallbackEventReference(Page, "argument", "processCallbackResult", "context", "processCallbackError", true); #region ICallbackEventHandler 成員 public string GetCallbackResult() &
8、#160; return smapstring; public void RaiseCallbackEvent(string eventArgument) /請求字符串 NameValueCollection keyValColl = CallbackUtility.ParseStringIntoN
9、ameValueCollection(eventArgument); if (keyValColl"Type".ToString() = "findPath") System.Text.StringBuilder sb = new System.Text.S
10、tringBuilder(); /起點名稱 string Input1 = keyValColl"p1" /終點名稱
11、0; string Input2 = keyValColl"p2" /路徑分析 doFindPath(Input1, Input2);
12、 #endregion /查詢最短路徑的主體函數(shù) private void doFindPath(string name1, string name2) /ags的服務器名 string SERVER_NAME = "ZHOUWEN" /ags
13、里發(fā)布的Map Service名 string ROUTE_SERVICE_NAME = "SanFrancisco" /創(chuàng)建NAServerProxy NAServerProxy naServerProxy = NAServerProxy.Create(SERVER_NAME, ROUTE_SERVICE_NAME, nul
14、l); if (naServerProxy = null) naServerProxy.Dispose(); throw (new System.Exception(
15、"Error"); else /獲取網(wǎng)絡層的名稱 string nLayers = naServ
16、erProxy.GetNALayerNames(esriNAServerLayerType.esriNAServerRouteLayer); NAServerSolverParams solverParams = naServerProxy.GetSolverParameters(nLayers0) as NAServerSolve
17、rParams; /路由分析參數(shù) NAServerRouteParams routeParams = solverParams as NAServerRouteParams; /不返回地圖
18、160; routeParams.ReturnMap = false; /返回RouteGeometries routeParams.ReturnRouteGeometries = true;
19、 routeParams.ReturnStops = true; routeParams.ReturnDirections = true; /設置起點PropertySet參數(shù)
20、160; PointN point = QueryPoint(name1); PropertySet propSet = new PropertySet(); PropertySetProperty propSetProperty_new = new Proper
21、tySetProperty2; propSet.PropertyArray = propSetProperty_new; PropertySetProperty propSetProperty = new PropertySetProperty(); &
22、#160; propSetProperty.Key = "Shape" propSetProperty.Value = point; PropertySetProperty propSetProperty2 = new PropertySetPropert
23、y(); propSetProperty2.Key = "Name" propSetProperty2.Value = name1; propSet.PropertyArr
24、ay0 = propSetProperty; propSet.PropertyArray1 = propSetProperty2; /設置終點PropertySet參數(shù) PointN poin
25、t2 = QueryPoint(name2); PropertySet propSet2 = new PropertySet(); PropertySetProperty propSetProperty_new2 = new PropertySetProperty2;
26、0; propSet2.PropertyArray = propSetProperty_new2; PropertySetProperty propSetProperty3 = new PropertySetProperty(); propSetProperty3
27、.Key = "Shape" propSetProperty3.Value = point2; PropertySetProperty propSetProperty4 = new PropertySetProperty();
28、60; propSetProperty4.Key = "Name" propSetProperty4.Value = name2; propSet2.PropertyArray0 = propSetProperty3; &
29、#160; propSet2.PropertyArray1 = propSetProperty4; /設置Stops參數(shù) PropertySet propSets = new PropertySet2; &
30、#160; propSets0 = propSet; propSets1 = propSet2; NAServerPropertySets StopsPropSets = new NAServerPropertySets(); &
31、#160; StopsPropSets.PropertySets = propSets; routeParams.Stops = StopsPropSets; NAServerSolverResults solverResults;
32、0; try /進行分析
33、; solverResults = naServerProxy.Solve(solverParams); NAServerRouteResults RouteSolverResults = solverResults as NAServerRouteResults;
34、; /顯示分析結果 ShowResults(solverResults); /釋放naServerProxy
35、 naServerProxy.Dispose(); catch (Exception e) &
36、#160; /釋放naServerProxy naServerProxy.Dispose();
37、 smapstring = Map1.CallbackResults.ToString(); /在地圖上展示最短路徑 public void ShowResults(NAServerSolverResults solverResults)
38、; NAServerRouteResults RouteSolverResults = solverResults as NAServerRouteResults; /開始點終點路徑顯示 AddRoutesAndStops(RouteSolverResults); /路徑區(qū)域全屏顯示
39、160; PolylineN polylineN = RouteSolverResults.RouteGeometries0 as PolylineN; EnvelopeN envelopeN = polylineN.Extent as EnvelopeN; double width = envelopeN.XMax - envelopeN.XMin;
40、160; double height = envelopeN.YMax - envelopeN.YMin; double fivePercent; if (width > height) fiveP
41、ercent = width * .05; else fivePercent = height * .05;
42、60; envelopeN.XMin = envelopeN.XMin - fivePercent; envelopeN.YMin = envelopeN.YMin - fivePercent; envelopeN.XMax = envelopeN.XMax + fivePercent;
43、 envelopeN.YMax = envelopeN.YMax + fivePercent; Map1.Extent = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfEnvelope(envelopeN); Map1.Refresh(); private void AddRoutesAndStops(NAServer
44、RouteResults rResult) /分析結果路徑 Polyline lines = rResult.RouteGeometries; RecordSet stops = rResult.Stops; /獲取Buffe
45、r的MapFunctionality ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality mapFunct = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)Map1.GetFunctionality("pathLayer"); /獲取Buffer的MapResource
46、160; ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource gResource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)mapFunct.Resource; /把buffer結果范圍進行顯示 ESRI.ArcGIS.ADF.Web.
47、Display.Graphics.ElementGraphicsLayer glayer = null; /查找ElementGraphicsLayer在Buffer中 foreach (System.Data.DataTable dt in gResource.Graphics.Tables) &
48、#160; if (dt is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer) glayer = (ESRI.ArcGIS.ADF.Web.Di
49、splay.Graphics.ElementGraphicsLayer)dt; break; /如果Buffer中沒
50、有ElementGraphicsLayer就新增加一個ElementGraphicsLayer if (glayer = null) glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
51、60; gResource.Graphics.Tables.Add(glayer); /清除ElementGraphicsLayer中的內容 glayer.Clear();
52、60; ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPolyline(PolylineN)lines0); /設置點顯示 ESRI.ArcGIS.ADF.Web.Display
53、.Graphics.GraphicElement ge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom, System.Drawing.Color.Red); /設置透明度 ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol sls = new ESRI.ArcGIS.ADF.Web.Display.
54、Symbol.SimpleLineSymbol(); sls.Width = 5; sls.Color = System.Drawing.Color.Blue; sls.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.LineType.Dash;
55、60; sls.Transparency = 50; ge.Symbol = sls; / ge.Symbol.Transparency = 50; /添加到Buffer中進行顯示 glayer.Add(ge);
56、160; Record stopRecords = stops.Records; int stopCount = stopRecords.Length; for (int iStop = 0; iStop < stopCount; iStop+)
57、; ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom2 = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPoint(stopRecordsiStop.Values1 as PointN); /設置點顯示
58、160; ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge2 = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom2, System.Drawing.Color.Red); /設置透明度
59、60; ge2.Symbol.Transparency = 50; /添加到Buffer中進行顯示 glayer.Add(ge2);
60、; /按名稱查找點 private PointN QueryPoint(string name) PointN point = new PointN(); IEnumerable func_enum = Map1.GetFunctionalities();
61、160; DataTable dt = null; foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality gisfunctionality in func_enum) if (gisfunctionality.
62、Resource.Name = "SanFrancisco") bool supported = false;
63、 ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = gisfunctionality.Resource; supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality);
64、; if (supported) &
65、#160; ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);
66、0; string lids; string lnames; qfunc.GetQu
67、eryableLayers(null, out lids, out lnames); ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();
68、; spatialfilter.ReturnADFGeometries = false; spatialfilter.MaxRecords = 1;
69、0; spatialfilter.WhereClause = "NAME LIKE '" + name + "'" spatialfilter.Geometry = Map1.GetF
70、ullExtent(); dt = qfunc.Query(null, lids3, spatialfilter); /lnames名稱
71、0; /0: "Stops" /1: "Barriers" /2:
72、"Routes" /3: "Facilities" /4: "Incidents" &
73、#160; /5: "Barriers" /6: "Routes" /7: "Facilities"
74、0; /8: "Barriers" /9: "Lines"
75、; /10: "Polygons" /11: "Hospital" /12: "bayareamultiroutestops"
76、60; /13: "bayareaincident" /14: "bayareafacilities" /15: "HwySt"
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 紡織設備質量控制體系與認證考核試卷
- 疫苗冷鏈管理與優(yōu)化考核試卷
- 冷凍飲品生產(chǎn)過程中的節(jié)能減排考核試卷
- 搪瓷表面裝飾工藝與設備考核試卷
- 生物制藥用儀器儀表制造技術考核試卷
- 纖維素纖維的生產(chǎn)過程與質量控制考核試卷
- 兒童游樂設備教育意義探討考核試卷
- 礦石提取與回收利用技術考核試卷
- 江蘇省常州市金壇區(qū)2025年數(shù)學四下期末達標檢測模擬試題含解析
- 濟寧職業(yè)技術學院《大學生職業(yè)規(guī)劃》2023-2024學年第一學期期末試卷
- DZ/T 0430-2023 固體礦產(chǎn)資源儲量核實報告編寫規(guī)范(正式版)
- JCT 2126.6-2012 水泥制品工藝技術規(guī)程 第6部分:先張法預應力混凝土管樁
- 第15課 十月革命的勝利與蘇聯(lián)的社會主義實踐 導學案
- 一年級數(shù)學20以內加減法口算題(每天100道)
- 螺旋天線報告
- 2024年中鐵集裝箱運輸有限責任公司招聘筆試參考題庫附帶答案詳解
- 物業(yè)管理中英文對照外文翻譯文獻
- 冠心病中西醫(yī)結合治療
- 腰椎人工椎體置換術
- 《物業(yè)客服培訓》課件
- 實習中遇到的問題
評論
0/150
提交評論