silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight 4系列 +VS2010 + ArcGIS9.3 最短路径分析大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

废话不多说,如题。      (1)数据获取及建立数据集        不同类型的空间分析需要不同类型的数据,对于最短路径分析,需要的数据是网络数据集。具体过程如下:打开一个shapefile格式的polyline图层,这里采用道路中心线图层(道路中心线.shp数据);         将“道路中心线.shp”数据转换为网络数据集:在ArcCatalog中,图层右键,选择New NetWork D
废话不多说,如题。

     (1)数据获取及建立数据集

       不同类型的空间分析需要不同类型的数据,对于最短路径分析,需要的数据是网络数据集。具体过程如下:打开一个shapefile格式的polyline图层,这里采用道路中心线图层(道路中心线.shp数据);

        将“道路中心线.shp”数据转换为网络数据集:在ArcCatalog中,图层右键,选择New NetWork Dataset;

通过对Network Dataset命名,设定数据源,创建连通性,指定高程数据,指定转弯数据源,定义属性,确定方向规则。即可生成的网络数据集包括“道路中心线_ND”网络数据集和“道路中心线_ND-Junctions”点状shp数据。

         在创建的过程中需要注意数据的字段是否有设置网络阻力信息的属性值:距离、旅行时间等等。确定方向规则貌似需要很多额外的字段,如果没有最后一步的direction是灰的,我照着示例数据(那个旧金山的)添加了几个类型为TEXT的字段,然后为空,即可。

      (2)最短路径建模及发布

        在ArcGIS中创建一个新的工具箱,命名为RoutIng,并在工具箱的基础上新建模型,命名为ShortesRoute。

       对于最短路径模型,需要虑的输入参数有三个:网络数据集、位置点以及障碍点,其中,网络数据集在运行前已经指定,不用动态输入,位置点和障碍点需要动态数据,位置点必须大于等于两个。

    建模过程:

A、Network Analyst Tools->Analysis->Make Route Layer,在输入网络集中选择之前声称的道路中心线_nd,选择输出的图层名为Route

 

B、Network Analyst Tools->Analysis->Add LOCATIOns为模型添加两个输入点:位置点和障碍点,分别设置Sub Layer中设置为Stops和Barriers。

C、Network Analyst Tools->Analysis->Solve 添加Solve(处理)节点;

D、Data Management Tools->General-> SELEct Date 以及Network Analyst Tools->Analysis->Directions添加输出结果节点,一种是以xml形式来对路径进行描述,一种是直接生成附加图层,生成的最终模型如下图:

 

                                                       

Silverlight 4系列 +VS2010 + ArcGIS9.3 最短路径分析

        加图有些麻烦,就放个成图吧。

        为了方便地图的显示和处理,将地图和gp文档相分离,将道路中心线_ND与制作的模型保存为一个地图文档,将其他的数据保存为一个地图文档:XXXXGP.mxdXXXX.mxd

XXXX.mxd@H_317_63@mapservices的形式发布,将XXXXGP.mxdGPservices的形式发布。

       

        (3)代码实现部分

        A、地图服务地址:

http://localhost/arcgis/rest/services/XXXX/MapServer

       B、GP服务地址:

http://localhost/arcgis/rest/services/XXXXGP/GPServer/ShortestRoute

       C、存放位置点和障碍点的数据集:

locaFS = new FeatureSet();

barrFS = new FeatureSet();

       D、最终的图层显示图层:

shortestGraLayer = map1.Layers["ShortestRouts"] as GraphicsLayer;

        E、鼠标点击添加位置点和障碍点:

  1. private void map1_MouseClick(object sender, Map.MouseEventArgs E)  
  2.   
  3.         {  
  4.   
  5.  Graphic graphic;    
  6.   
  7.             if (_pointType == pointType.LOCATIOn)  
  8.   
  9.             {  
  10.   
  11.                 graphic = new Graphic()  
  12.   
  13.                 {  
  14.   
  15.                     Symbol = LayoutRoot.resources["GreenMarkerSymbol"] as Symbol,  
  16.   
  17.                     Geometry = e.MapPoint,  
  18.   
  19.                 };  
  20.   
  21.                  locaFs.Features.Add(graphic);  
  22.   
  23.             }  
  24.   
  25.             else if (_pointType == pointType.barrier)  
  26.   
  27.             {  
  28.   
  29.                 graphic = new Graphic()  
  30.   
  31.                 {  
  32.   
  33.                     Symbol = LayoutRoot.resources["RedMarkerSymbol"] as Symbol,  
  34.   
  35.                 };  
  36.   
  37.                 barrFs.Features.Add(graphic);  
  38.   
  39.             }      
  40.   
  41.             else  
  42.   
  43.             {  
  44.   
  45.                 return;  
  46.   
  47.             }  
  48.   
  49.             shortestGraLayer.Graphics.Add(graphic);  
  50.   
  51.         }  
  52. @H_892_262@
private void map1_MouseClick(object sender,Map.MouseEventArgs E)        { Graphic graphic;              if (_pointType == pointType.LOCATIOn)            {                graphic = new Graphic()                {                    Symbol = LayoutRoot.resources["GreenMarkerSymbol"] as Symbol,Geometry = e.MapPoint,};                 locaFs.Features.Add(graphic);            }            else if (_pointType == pointType.barrier)            {                graphic = new Graphic()                {                    Symbol = LayoutRoot.resources["RedMarkerSymbol"] as Symbol,};                barrFs.Features.Add(graphic);            }                else            {                return;            }            shortestGraLayer.Graphics.Add(graphic);        }


      F、最短路径分析执行GP服务:

  1. shortestRoutGP = new Geoprocessor("http://localhost/arcgis/rest/services/XXXXGP /GPServer/ShortestRoute");  
  2.   
  3. shortestRoutGP.ExecuteCompleted += new EventHandler<GPExecuteCompleteEventArgs>(shortestRoutGP_ExecuteCompleted);  
  4.   
  5.      shortestRoutGP.@L_489_32@ += new EventHandler<Task@L_489_32@EventArgs>(shortestRoutGP_@L_489_32@);  
  6.   
  7.          shortestRoutGP.ExecuteAsync(parameters);  
  8.   
  9. void shortestRoutGP_ExecuteCompleted(object sender, GPExecuteCompleteEventArgs E)  
  10.   
  11.         {  
  12.   
  13.             //shortestGraLayer.Graphics.Clear();  
  14.   
  15.             foreach (GPParameter parameter in e.Results.OutParameters)  
  16.   
  17.             {  
  18.   
  19.                 if (parameter is GPFeatureRecordSetLayer)  
  20.   
  21.                 {  
  22.   
  23.                     GPFeatureRecordSetLayer gpLayer = parameter as GPFeatureRecordSetLayer;  
  24.   
  25.                     Graphic graphic = new Graphic()  
  26.   
  27.                     {  
  28.   
  29. Symbol = LayoutRoot.resources["BlueLinesymbol"] as Symbol,  
  30.   
  31.                         Geometry = gpLayer.FeatureSet.Features[0].Geometry,  
  32.   
  33.                     };  
  34.   
  35.                     shortestGraLayer.Graphics.Add(graphic);  
  36.   
  37.                 }  
  38.   
  39.             }  
  40.   
  41.             parameters.Clear();  
  42.   
  43.         }  
  44. @H_892_262@
shortestRoutGP = new Geoprocessor("http://localhost/arcgis/rest/services/XXXXGP /GPServer/ShortestRoute");shortestRoutGP.ExecuteCompleted += new EventHandler<GPExecuteCompleteEventArgs>(shortestRoutGP_ExecuteCompleted);     shortestRoutGP.@L_489_32@ += new EventHandler<Task@L_489_32@EventArgs>(shortestRoutGP_@L_489_32@);         shortestRoutGP.ExecuteAsync(parameters);void shortestRoutGP_ExecuteCompleted(object sender,GPExecuteCompleteEventArgs E)        {            //shortestGraLayer.Graphics.Clear();            foreach (GPParameter parameter in e.Results.OutParameters)            {                if (parameter is GPFeatureRecordSetLayer)                {                    GPFeatureRecordSetLayer gpLayer = parameter as GPFeatureRecordSetLayer;                    Graphic graphic = new Graphic()                    {Symbol = LayoutRoot.resources["BlueLinesymbol"] as Symbol,Geometry = gpLayer.FeatureSet.Features[0].Geometry,};                    shortestGraLayer.Graphics.Add(graphic);                }            }            parameters.Clear();        }

具体细节不累述,核心代码就这些啦。

大佬总结

以上是大佬教程为你收集整理的Silverlight 4系列 +VS2010 + ArcGIS9.3 最短路径分析全部内容,希望文章能够帮你解决Silverlight 4系列 +VS2010 + ArcGIS9.3 最短路径分析所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。