cl991036
管理员
管理员
  • 注册日期2003-07-25
  • 发帖数5913
  • QQ14265545
  • 铜币29657枚
  • 威望213点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • GIS帝国铁杆
阅读:1485回复:0

[转帖]再写关于ArcGIS Server的最短路径

楼主#
更多 发布于:2008-06-04 09:32

<P ><U ><FONT style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px" color=#ff0000>本文版权归小能所有,转载麻烦标明出处,谢谢! 同时写作过程中也参阅了大量其他网络文档,如果您觉得侵犯版权,请和我联系:</FONT></U><a href="mailtchinazhousheng@gmail.com" target="_blank" ><FONT style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px" color=#ff0000>chinazhousheng@gmail.com</FONT></A></P>
<P >    前几天在群里面有朋友问我最短路径的事,他想实现一个可能分别在地图上取点设置起点与终点的功能,由于最近很多事情,所以一直没有做,昨天花了一点时间,做了一下,其实还是一个状态保存的问题,其思路如下:</P>
<P >step1 :获取起点的坐标,并保存至session  中</P>
<P >step2:获取终点坐标,判断session中是否有值,如果有,则获取起点</P>
<P >step3:计算最短路径(这在前面已经说过,稍微改变一下)</P>
<P >step4:清除session</P>
<P >大体思路就是这样,当然还有其他的思路,希望大家实现后共享,这次的代码很简单,我简单的发一点!</P><BR >
<DIV ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>//获取屏幕点,并转换成Map点<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>      ESRI.ArcGIS.ADF.Web.Geometry.Point pnt = new ESRI.ArcGIS.ADF.Web.Geometry.Point();<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>      ESRI.ArcGIS.ADF.Web.UI.WebControls.PointEventArgs ptargs = null;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>      ptargs = (PointEventArgs)args;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>      pnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(ptargs.ScreenPoint.X, ptargs.ScreenPoint.Y, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> <BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>if (System.Web.HttpContext.Current.Session["beg_point"]==null)<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top>       {<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>           System.Web.HttpContext.Current.Session["beg_point"] = pnt;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> <BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>else<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top>       {<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>try<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top>          {<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>              // Get the NAServer<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>              using (NAServerProxy naServer = NAServerProxy.Create(SERVER_NAME, ROUTE_SERVICE_NAME, null))<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top>              {<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  if (naServer == null)<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                      throw (new System.Exception("Could not find the web service."));<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  // Get the NAServerSolverParams<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  string[] naLayers = naServer.GetNALayerNames(esriNAServerLayerType.esriNAServerRouteLayer);<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  NAServerSolverParams solverParams = naServer.GetSolverParameters(naLayers[0]) as NAServerSolverParams;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  // Set the NAServerRouteParams<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  NAServerRouteParams routeParams = solverParams as NAServerRouteParams;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  DateTime time;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  routeParams.ReturnMap = false;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  routeParams.ReturnRouteGeometries = true;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  routeParams.ReturnStops = true;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  routeParams.ReturnDirections = false;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  // Geocode two addresses and create the stop network locations<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  NetAnalysis location = new NetAnalysis(mapctrl);<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top>                  ////<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  PropertySet[] propSets = new PropertySet[2];<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  propSets[0] = GeocodeAddress(beg_point.X, beg_point.Y);//<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  propSets[1] = GeocodeAddress(pnt.X, pnt.Y);//<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  NAServerPropertySets StopsPropSets = new NAServerPropertySets();<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  StopsPropSets.PropertySets = propSets;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  NAServerRouteParams routeParams1 = solverParams as NAServerRouteParams;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  routeParams1.Stops = StopsPropSets;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top>                  /////<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  // Solve the Route<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  NAServerSolverResults solverResults;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  solverResults = naServer.Solve(solverParams);<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  // Display results<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>                  location.OutputResults(solverResults);<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>              }<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>          }<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>          catch (Exception exception)<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top>          {<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>              //pnlDirectionSummary.Visible = false;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>              //lblDirections.Visible = false;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>              //lblTotalDistance.Visible = false;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>              //dataGridDirections.Visible = false;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>              lblError.Text = "An error has occurred Mesage = " + exception.Message;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>          } <BR ></DIV>
<DIV ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>private PropertySetProperty CreatePropertySetProperty(string key, object value)<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top>    {<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        PropertySetProperty propSetProperty = new PropertySetProperty();<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        propSetProperty.Key = key;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        propSetProperty.Value = value;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        return propSetProperty;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>    }<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>    private PropertySet GeocodeAddress(double streetAddress_x, double streetAddress_y)<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top>    {<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        //寻找地理位置<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        PointN addr_point = new PointN() ;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        addr_point.X = streetAddress_x;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        addr_point.Y = streetAddress_y;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        //新建propertyset及PropertySetProperty数组<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        PropertySet propSet = new PropertySet();<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        PropertySetProperty[] propSetProperty_new = new PropertySetProperty[2];<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        propSet.PropertyArray = propSetProperty_new;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        //设置propSet结构<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        propSet.PropertyArray[0] = CreatePropertySetProperty("Shape", addr_point) as PropertySetProperty;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        propSet.PropertyArray[1] = CreatePropertySetProperty("Name", "44") as PropertySetProperty;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>        return propSet;<BR ><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>    }</DIV>
<P >当然,可以添加效果,比如点击起点后,在地图上画一个标志!下面是结果图</P>
<P ><a href="http://www.cnblogs.com/images/cnblogs_com/chinazhousheng/WindowsLiveWriter/ArcGISServer_7CAB/image_2.png" target="_blank" ><IMG src="http://www.cnblogs.com/images/cnblogs_com/chinazhousheng/WindowsLiveWriter/ArcGISServer_7CAB/image_thumb.png" border=0></A></P>
喜欢0 评分0
没钱又丑,农村户口。头可断,发型一定不能乱。 邮箱:gisempire@qq.com
游客

返回顶部