分享
分销 收藏 举报 申诉 / 10
播放页_导航下方通栏广告

类型ArcGIS Server 开发系列(七)--物流配送.doc

  • 上传人:二***
  • 文档编号:4479919
  • 上传时间:2024-09-24
  • 格式:DOC
  • 页数:10
  • 大小:471KB
  • 下载积分:5 金币
  • 播放页_非在线预览资源立即下载上方广告
    配套讲稿:

    如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

    特殊限制:

    部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

    关 键  词:
    ArcGIS Server 开发系列七--物流配送 开发 系列 物流配送
    资源描述:
    . ArcGIS Server 开发系列(七)--物流配送 2008-12-31 15:58 by Flyingis, 5230 visits, 作者:Flyingis     ArcGIS Server开发系列的文章至今已经一年多了,虽然文章只有短短六篇,也比较基础,但值得高兴的是帮助了不少第一次接触ArcGIS Server的开发者,现在不少都已经完成一两个项目了,相信收获不小,有时间可以和大家一起分享经验。今天开始,我们将继续这个系列教程,争取覆盖ADF开发常用功能,以帮助更多的人轻松入门ADF开发。     目标:    实现简易的物流配送(VRP)     准备工作:     1.重新复习《ArcGIS Server 开发系列(六)--自定义 Tasks》     2.准备数据 "%ArcGISInstallDir%\DeveloperKit\SamplesNET\Server\data\SanFranciscoNetwork"     3.发布NATasks.mxd地图服务,添加Network Analyst功能服务     4.MapResourceManager中添加一个ArcGIS Server Local类型服务     在这个应用中,多车配送的功能封装为一个自定义的Task,然后生成一个dll添加到ASP.Net工具箱中,由Web Mapping Application的Task Manager调用,更改自定义Task的Task Results Container为模板应用中的TaskResults1控件。     Web Mapping Application大家已经非常熟悉,现在的重点就在如何利用ArcGIS Server实现VRP功能。VRP全称vehicle routing problem,属于NP难问题,基本没有统一的方法来解决所有的VRP问题,只能根据具体的情况采用最合适的算法,咱们下面就利用ArcGIS Server模拟一个简单的应用场景,实现多车物流的配送计算。     自定义Task,需要构建Task的UI和业务逻辑,UI构建通过重写方法CreateChildControls完成,咱们最终实现的效果: 相应的代码比较容易看懂,结合上面实现的UI效果图和代码注释就能明白每部分代码所完成的功能,实现代码: protected override void CreateChildControls(){ Controls.Clear(); base.CreateChildControls(); Create top level table#region Create top level table System.Web.UI.WebControls.Table table = new System.Web.UI.WebControls.Table(); table.Width = System.Web.UI.WebControls.Unit.Pixel(240); Controls.Add(table); TableRow tr; TableCell td; #endregion Orders Label#region Orders Label tr = new TableRow(); td = new TableCell(); td.Text = "Select orders to service"; tr.Cells.Add(td); table.Rows.Add(tr); #endregion Create and populate orders Listbox#region Create and populate orders Listbox _oids = new List<int>(); _ordersCheckBoxList = new CheckBoxList(); _ordersCheckBoxList.ID = "OrdersCheckBoxList"; _ordersCheckBoxList.Width = System.Web.UI.WebControls.Unit.Point(200); IServerContext serverContext = MapResourceLocal.ServerContextInfo.ServerContext; IMap vrpMap = Utility.GetCartoIMap(MapInstance, "NA_MapResourceItem"); IFeatureLayer ordersInputFLayer = Utility.GetFeatureLayer("Stores", vrpMap); IFeatureClass ordersInputFClass = ordersInputFLayer.FeatureClass; int nameIndex = ordersInputFClass.FindField("Name"); IFeatureCursor ordersInputFCursor = ordersInputFClass.Search(null, false); IFeature orderFeature = ordersInputFCursor.NextFeature(); while (orderFeature != null) { ListItem li = new ListItem(orderFeature.get_Value(nameIndex).ToString()); li.Selected = true; _ordersCheckBoxList.Items.Add(li); _oids.Add(orderFeature.OID); orderFeature = ordersInputFCursor.NextFeature(); } #endregion OrdersPanel#region OrdersPanel tr = new TableRow(); td = new TableCell(); Panel ordersPanel = new Panel(); ordersPanel.Height = 200; ordersPanel.Width = 240; ordersPanel.BorderColor = System.Drawing.Color.Black; ordersPanel.BorderStyle = BorderStyle.Inset; ordersPanel.BorderWidth = 1; ordersPanel.ScrollBars = ScrollBars.Vertical; ordersPanel.Controls.Add(_ordersCheckBoxList); td.Controls.Add(ordersPanel); tr.Cells.Add(td); table.Rows.Add(tr); #endregion Get Directions Button#region Get Directions Button tr = new TableRow(); tr.Attributes.Add("align", "right"); td = new TableCell(); td.ColumnSpan = 2; HtmlInputButton button = new HtmlInputButton(); button.Value = "Get Directions"; button.ID = "execute"; td.Controls.Add(button); tr.Cells.Add(td); table.Rows.Add(tr); #endregion OnClick Event for executing task#region OnClick Event for executing task string argument = string.Format("'selectedIndexes=' + getCheckedItemIndexes('{0}', '{1}')", _ordersCheckBoxList.ClientID, _ordersCheckBoxList.Items.Count); string onClick = string.Format("executeTask({0},\"{1}\");", argument, CallbackFunctionString); button.Attributes.Add("onclick", onClick); #endregion // Access the graphics layer so it is created and shown in the TOC ElementGraphicsLayer pointsGraphicsLayer = PointsGraphicsLayer;}     CreateChildControls用于构建VRPTask UI,除了界面要素之外,还需要从源数据中读取商店信息,如读取商店名称显示在界面上,当VRPTask中的商店被勾选上时,车辆将为该商店送货。商店供货信息存储在数据源中单独的一个图层中stores.shp,包含商店所需的货物数量和预计提供服务的时间。      VRPTask UI完成之后,接下来要设计VRP的业务逻辑,ArcGIS 9.3 Network Extension提供了一个基本的VRP解决方案,因此我们在发布NATasks服务的时候需要勾选Network Analyst功能,通过ServerContext去远程调用AO方法。     第一步,获取VRP分析图层。 IServerContext serverContext = MapResourceLocal.ServerContextInfo.ServerContext;IMap vrpMap = Utility.GetCartoIMap(MapInstance, "NA_MapResourceItem");IGPMessages gpMessages = serverContext.CreateObject("esriGeodatabase.GPMessages") as IGPMessages;INALayer2 vrpNALayer = Utility.GetNALayer("Vehicle Routing Problem", vrpMap);INAContext vrpNAContext = vrpNALayer.CopyContext();INAContextEdit vrpNAContextEdit = vrpNAContext as INAContextEdit;vrpNAContextEdit.Bind(vrpNALayer.Context.NetworkDataset, gpMessages);     第二步,获取配送中心信息、商店信息、车辆信息和司机午餐时间。 IFeatureLayer depotsInputFLayer = Utility.GetFeatureLayer("DistributionCenters", vrpMap);IFeatureClass depotsInputFClass = depotsInputFLayer.FeatureClass;IFeatureCursor depotsInputFCursor = depotsInputFClass.Search(null, false);LoadAnalysisClass(serverContext, vrpNAContext, "Depots", depotsInputFCursor as ICursor);// Load OrdersIFeatureLayer ordersInputFLayer = Utility.GetFeatureLayer("Stores", vrpMap);IFeatureClass ordersInputFClass = ordersInputFLayer.FeatureClass;IFeatureCursor ordersInputFCursor = ordersInputFClass.GetFeatures(oids, true);LoadAnalysisClass(serverContext, vrpNAContext, "Orders", ordersInputFCursor as ICursor);// Load the RoutesITable routesInputTable = Utility.GetStandaloneTable("Vehicles", vrpMap).Table;ICursor routesInputCursor = routesInputTable.Search(null, true);LoadAnalysisClass(serverContext, vrpNAContext, "Routes", routesInputCursor as ICursor);// Load the BreaksITable breaksInputTable = Utility.GetStandaloneTable("LunchBreaks", vrpMap).Table;ICursor breaksInputCursor = breaksInputTable.Search(null, true);LoadAnalysisClass(serverContext, vrpNAContext, "Breaks", breaksInputCursor as ICursor);// Message all of the network analysis agents that the analysis context has changedvrpNAContextEdit.ContextChanged();     配送中心、商店信息均存储在物理图层中,分别对应DistributionCenters.shp、Stores.shp,车辆信息和司机午餐时间存储于Table表中。车辆Table包含物流配送过程中和车辆相关的一切信息,如起止配送中心、承载量、最多订单数、发车时间、最长驾驶时间、最长行驶距离等,司机午餐Table包含允许的午餐持续时间、允许的午餐时间X围等,这些都将用于ArcGIS VRP模型的计算中。     第三步,路径计算,做过ArcEngine Network Analyst开发的工程师对INASolver、INAVRPSolver一定非常熟悉了,调用过程比较简单,路径计算的同时处理系统反馈的消息信息。 gpMessages.Clear();INASolver naSolver = vrpNAContext.Solver;INAVRPSolver vrpSolver = naSolver as INAVRPSolver;vrpSolver.GenerateInternalRouteContext = true; // Required for true-shape and directionsvrpSolver.DefaultDate = DateTime.Today;        // Set the default date to be todaybool partialResults = naSolver.Solve(vrpNAContext, gpMessages, null);// report errorsif (partialResults || gpMessages.Count > 0){ StringBuilder sErrors = new StringBuilder(); for (int i = 0; i < gpMessages.Count; i++) sErrors.AppendLine(gpMessages.GetMessage(i).Description); Results = sErrors.ToString(); return;}     第四步,处理结果,VRP计算后最重要的结果就是生成的车辆分配情况、配送顺序和车辆配送路径,将车辆行驶的详细信息以图文并茂的方式展示出来。 // Get Map's Spatial Reference (to project output geometriesESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality mf = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)MapInstance.GetFunctionality("NA_MapResourceItem");SpatialReference mapSpatialReference = mf.MapDescription.SpatialReference;// Output result Routes and StopsUtility.OutputRoutesAsGraphics(serverContext, vrpNAContext, RoutesGraphicsLayer, mapSpatialReference);Utility.OutputOrdersAsGraphics(serverContext, vrpNAContext, PointsGraphicsLayer, mapSpatialReference);// Create results nodeTaskResultNode parentTaskResultNode = Utility.CreateTaskResultNode("VRP Results");parentTaskResultNode.Expanded = true;// Get the Route Context from the results to use for directionsINAVRPResult vrpResult = vrpNAContext.Result as INAVRPResult;INAContext routeNAContext = vrpResult.InternalRouteContext;// Loop through the resulting routes and add items for each route (vehicle)ISet routeSet = serverContext.CreateObject("esriSystem.Set") as ISet;IFeatureClass routeRoutesFClass = routeNAContext.NAClasses.get_ItemByName("Routes") as IFeatureClass;int routeNameIndex = routeRoutesFClass.FindField("Name");IFeatureCursor routesRouteFCursor = routeRoutesFClass.Search(null, false);int routeNumber = 0;IFeature routeFeature = routesRouteFCursor.NextFeature();while (routeFeature != null){ string routeName = routeFeature.get_Value(routeNameIndex).ToString(); Choose color for each route#region Choose color for each route TaskResultNode routeTaskResultNode = Utility.CreateTaskResultNode(routeName); routeTaskResultNode.TextCellStyleAttributes.Add("font-weight", "bold"); routeTaskResultNode.TextCellStyleAttributes.Add("font-size", "12"); if (routeNumber == 0) routeTaskResultNode.TextCellStyleAttributes.Add("color", System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.Blue)); else if (routeNumber == 1) routeTaskResultNode.TextCellStyleAttributes.Add("color", System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.Purple)); else if (routeNumber == 2) routeTaskResultNode.TextCellStyleAttributes.Add("color", System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.Green)); else if (routeNumber == 3) routeTaskResultNode.TextCellStyleAttributes.Add("color", System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.Brown)); #endregion routeTaskResultNode.Expanded = true; parentTaskResultNode.Nodes.Add(routeTaskResultNode); // Add Statistics TaskResultNode vrpRouteStatisticsNode = Utility.GetVRPRouteStatisticsNode(serverContext, vrpNAContext, routeName); vrpRouteStatisticsNode.TextCellStyleAttributes.Add("font-weight", "bold"); routeTaskResultNode.Nodes.Add(vrpRouteStatisticsNode); // Add Directions // Get the directions for the specified route routeSet.RemoveAll(); routeSet.Add(routeFeature);// Get Directions // Generate the directions TaskResultNode directionsTaskResultNode = Utility.GetDirectionsNode(false, routeNAContext, routeSet); directionsTaskResultNode.TextCellStyleAttributes.Add("font-weight", "bold"); // Add the directions to the results node routeTaskResultNode.Nodes.Add(directionsTaskResultNode); routeNumber++; routeFeature = routesRouteFCursor.NextFeature();}     通过上述过程,完成了VRPTask的UI设计和业务逻辑程序,之后需要将应用重新生成为dll,添加到ASP.Net工具箱中,方便WebGIS应用调用该Task控件,我们在Web Mapping Application模板应用程序基础上添加VRPTask,运行后效果:    数据源vehicles table中包含三辆汽车的记录,在应用中勾选需要进行配送的商店,     例如选择15家商店,点击"Get Directions"执行VRP计算,生成结果如下所示:    我们可以发现,很多路径配送需要考虑的问题ArcGIS VRP模型都提供了一套非常简便的解决方案,能够解决一般情况下的VRP问题,但是就如文章前面所说,VRP没有统一的解决方法,但是至少我们可以选择基于ArcGIS Server进行扩展,请思考:     1.地图数据结构。     2.配送分区怎么考虑。     3.配送效率测试。     4.结对订单。 专心.
    展开阅读全文
    提示  咨信网温馨提示:
    1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
    2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
    3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
    4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
    5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
    6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

    开通VIP折扣优惠下载文档

    自信AI创作助手
    关于本文
    本文标题:ArcGIS Server 开发系列(七)--物流配送.doc
    链接地址:https://www.zixin.com.cn/doc/4479919.html
    页脚通栏广告

    Copyright ©2010-2025   All Rights Reserved  宁波自信网络信息技术有限公司 版权所有   |  客服电话:0574-28810668    微信客服:咨信网客服    投诉电话:18658249818   

    违法和不良信息举报邮箱:help@zixin.com.cn    文档合作和网站合作邮箱:fuwu@zixin.com.cn    意见反馈和侵权处理邮箱:1219186828@qq.com   | 证照中心

    12321jubao.png12321网络举报中心 电话:010-12321  jubao.png中国互联网举报中心 电话:12377   gongan.png浙公网安备33021202000488号  icp.png浙ICP备2021020529号-1 浙B2-20240490   


    关注我们 :微信公众号  抖音  微博  LOFTER               

    自信网络  |  ZixinNetwork