//获取方向信息 private string getDirectionsString(INAStreetDirections serverDirections) { // 得到总的距离和时间 INAStreetDirection direction = serverDirections.Summary; string totallength = null, totaltime = null; for (int k = 0; k < direction.StringCount; k++) { if (direction.get_StringType(k) == esriDirectionsStringType.esriDSTLength) { totallength = direction.get_String(k); } if (direction.get_StringType(k) == esriDirectionsStringType.esriDSTTime) { totaltime = direction.get_String(k); } } //MessageBox.Show("Directions for CFRoute [" + (1) + "] - Total Distance: " + totallength + " Total Time: " + totaltime); string directionString = string.Empty; // 加节点到方向 for (int directionIndex = 0; directionIndex < serverDirections.DirectionCount; directionIndex++) { direction = serverDirections.get_Direction(directionIndex); for (int stringIndex = 0; stringIndex < direction.StringCount; stringIndex++) { if (direction.get_StringType(stringIndex) == esriDirectionsStringType.esriDSTGeneral || direction.get_StringType(stringIndex) == esriDirectionsStringType.esriDSTDepart || direction.get_StringType(stringIndex) == esriDirectionsStringType.esriDSTArrive || direction.get_StringType(stringIndex) == esriDirectionsStringType.esriDSTSummary ) { if (stringIndex == 0) { directionString += direction.get_String(stringIndex).ToString() + "|"; } else if (stringIndex == 2) { directionString += direction.get_String(stringIndex).ToString() + "@"; } } } } return(directionString); }
//路径分析 private void toolStripButton3_Click(object sender, EventArgs e) { if (global.networkAnalysis && global.clickedcount > 1) { global.networkAnalysis = false; listBox1.Items.Add("开始进行路径分析求解..."); IGPMessages gpMessages = new GPMessagesClass(); loadNANetworkLocations("Stops", global.inputFClass, 80); naSolver = global.m_NAContext.Solver; naSolver.Solve(global.m_NAContext, gpMessages, null); listBox1.Items.Add("done!"); //获取路径结果 INAStreetDirectionsAgent2 streetAgent; streetAgent = global.m_NAContext.Agents.get_ItemByName("StreetDirectionsAgent") as INAStreetDirectionsAgent2; //设置处理结果为中文 //streetAgent.Language = "zh-CN"; streetAgent.Execute(null, null); INAStreetDirectionsContainer directionsContainer; directionsContainer = streetAgent.DirectionsContainer as INAStreetDirectionsContainer; //directionsContainer.SaveAsXML("route.xml"); int directionsCount = directionsContainer.DirectionsCount; string routeIdName = string.Empty; string routeString; for (int index = 0; index < directionsCount; index++) { INAStreetDirections naStreetDirections = directionsContainer.get_Directions(index); routeString = getDirectionsString(naStreetDirections); getDataTableFromRouteString(routeString); } //解决完后,删除图层内容 ITable pTable_inputFClass = global.inputFClass as ITable; pTable_inputFClass.DeleteSearchedRows(null); (global.p2DMap as IActiveView).Refresh(); if (gpMessages != null) { for (int i = 0; i < gpMessages.Count; i++) { switch (gpMessages.GetMessage(i).Type) { case esriGPMessageType.esriGPMessageTypeError: listBox1.Items.Add("错误 " + gpMessages.GetMessage(i).ErrorCode.ToString() + " " + gpMessages.GetMessage(i).Description); break; case esriGPMessageType.esriGPMessageTypeWarning: listBox1.Items.Add("警告 " + gpMessages.GetMessage(i).Description); break; default: listBox1.Items.Add("信息 " + gpMessages.GetMessage(i).Description); break; } } } (global.p2DMap as IActiveView).Refresh(); } else if (global.clickedcount == 1) { MessageBox.Show("未选取终点,请继续定位!"); } else { MessageBox.Show("未选取或更新起点和终点,请重新定位!"); } }