ArcGIS Server 93 最短路徑分析_第1頁
ArcGIS Server 93 最短路徑分析_第2頁
ArcGIS Server 93 最短路徑分析_第3頁
ArcGIS Server 93 最短路徑分析_第4頁
ArcGIS Server 93 最短路徑分析_第5頁
已閱讀5頁,還剩14頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、ArcGIS Server 9.3 最短路徑分析要做網(wǎng)絡(luò)分析,首先你的arcgis server需要具有network analysis 擴(kuò)展模塊的license。其次需要網(wǎng)絡(luò)數(shù)據(jù)集,這個(gè)問題好解決,直接使用安裝目錄下的ArcGIS"DeveloperKit"SamplesNET"Server"data"SanFrancisco下的網(wǎng)絡(luò)數(shù)據(jù)集將其發(fā)布,發(fā)布時(shí)記得勾上NetWork Anaysis 這項(xiàng)。然后新建一個(gè)網(wǎng)站,加上常用的map,mapresourcemanager,toolbar,toc 控件等,在mapresourcemanager

2、中加入兩個(gè)資源,一個(gè)是graphicslayer類型,命名為 pathLayer,一個(gè)為ArcGIS Server Local類型,命名為SanFrancisco,并加上兩個(gè)textbox和一個(gè)按鈕,布置好后如圖1。首先在前臺(tái)的代碼如下:/函數(shù)search()即為所加按鈕的onclick對(duì)應(yīng)的函數(shù)。<script type="text/javascript">     function search()           

3、 /起點(diǎn)的名稱       var v1=document.getElementById("Text1").value;        /終點(diǎn)的名稱        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> 后臺(tái)還是callback機(jī)制來實(shí)現(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)           /請(qǐng)求字符串        NameValueCollection keyValColl = CallbackUtility.ParseStringIntoN

9、ameValueCollection(eventArgument);        if (keyValColl"Type".ToString() = "findPath")                    System.Text.StringBuilder sb = new System.Text.S

10、tringBuilder();            /起點(diǎn)名稱            string Input1 = keyValColl"p1"            /終點(diǎn)名稱     

11、0;      string Input2 = keyValColl"p2"            /路徑分析            doFindPath(Input1, Input2);           

12、 #endregion /查詢最短路徑的主體函數(shù)    private void doFindPath(string name1, string name2)            /ags的服務(wù)器名        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)絡(luò)層的名稱         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;             /設(shè)置起點(diǎn)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;             /設(shè)置終點(diǎn)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;             /設(shè)置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                            /進(jìn)行分析            

33、;    solverResults = naServerProxy.Solve(solverParams);                NAServerRouteResults RouteSolverResults = solverResults as NAServerRouteResults;          

34、;      /顯示分析結(jié)果                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;        /開始點(diǎn)終點(diǎn)路徑顯示        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)            /分析結(jié)果路徑        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結(jié)果范圍進(jìn)行顯示        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就新增加一個(gè)ElementGraphicsLayer        if (glayer = null)                    glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer(); 

51、60;          gResource.Graphics.Tables.Add(glayer);                /清除ElementGraphicsLayer中的內(nèi)容        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);        /設(shè)置點(diǎn)顯示        ESRI.ArcGIS.ADF.Web.Display

53、.Graphics.GraphicElement ge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom, System.Drawing.Color.Red);        /設(shè)置透明度        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中進(jìn)行顯示        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);            /設(shè)置點(diǎn)顯示&#

58、160;           ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge2 = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom2, System.Drawing.Color.Red);            /設(shè)置透明度  

59、60;         ge2.Symbol.Transparency = 50;            /添加到Buffer中進(jìn)行顯示            glayer.Add(ge2);          

60、;      /按名稱查找點(diǎn)    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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論