/// <summary> /// Occurs when this tool is clicked /// </summary> public override void OnClick() { // TODO: Add AddNetBarriesTool.OnClick implementation string name = NetWorkAnalysClass.getPath(path) + "\\data\\HuanbaoGeodatabase.gdb"; pFWorkspace = NetWorkAnalysClass.OpenWorkspace(name) as IFeatureWorkspace; barriesFClass = pFWorkspace.OpenFeatureClass("Barries"); if (barriesFClass.FeatureCount(null) > 0) { ITable pTable = barriesFClass as ITable; pTable.DeleteSearchedRows(null); } }
private void barButtonItem39_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { axMapControl1.CurrentTool = null; try { string name = NetWorkAnalysClass.getPath(path) + "\\data\\HuanbaoGeodatabase.gdb"; //打开工作空间 pFWorkspace = NetWorkAnalysClass.OpenWorkspace(name) as IFeatureWorkspace; IGraphicsContainer pGrap = this.axMapControl1.ActiveView as IGraphicsContainer; pGrap.DeleteAllElements();//删除所添加的图片要素 IFeatureClass inputFClass = pFWorkspace.OpenFeatureClass("Stops"); //删除站点要素 if (inputFClass.FeatureCount(null) > 0) { ITable pTable = inputFClass as ITable; pTable.DeleteSearchedRows(null); } IFeatureClass barriesFClass = pFWorkspace.OpenFeatureClass("Barries");//删除障碍点要素 if (barriesFClass.FeatureCount(null) > 0) { ITable pTable = barriesFClass as ITable; pTable.DeleteSearchedRows(null); } for (int i = 0; i < axMapControl1.LayerCount; i++)//删除分析结果 { ILayer pLayer = axMapControl1.get_Layer(i); if (pLayer.Name == ShortPathSolveCommand.m_NAContext.Solver.DisplayName) { axMapControl1.DeleteLayer(i); break; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } this.axMapControl1.Refresh(); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add ShortPathSolveCommand.OnClick implementation string name = "HuanbaoGeodatabase.gdb"; IFeatureWorkspace pFWorkspace = NetWorkAnalysClass.OpenWorkspace(name) as IFeatureWorkspace; //"RouteNetwork", "BaseData"参数不可更改 networkDataset = NetWorkAnalysClass.OpenPathNetworkDataset(pFWorkspace as IWorkspace, "RouteNetwork", "BaseData"); m_NAContext = NetWorkAnalysClass.CreatePathSolverContext(networkDataset); //通过网络数据集创建网络分析上下文 //打开要素数据集 inputFClass = pFWorkspace.OpenFeatureClass("Stops"); barriesFClass = pFWorkspace.OpenFeatureClass("Barries"); if (IfLayerExist("NetworkDataset") == false) { ILayer layer; INetworkLayer networkLayer; networkLayer = new NetworkLayerClass(); networkLayer.NetworkDataset = networkDataset; layer = networkLayer as ILayer; layer.Name = "NetworkDataset"; m_hookHelper.ActiveView.FocusMap.AddLayer(layer); layer.Visible = false; } if (IfLayerExist(m_NAContext.Solver.DisplayName) == true) { for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++) { if (m_hookHelper.FocusMap.get_Layer(i).Name == m_NAContext.Solver.DisplayName) { m_hookHelper.FocusMap.DeleteLayer(m_hookHelper.FocusMap.get_Layer(i)); } } } INALayer naLayer = m_NAContext.Solver.CreateLayer(m_NAContext); ILayer pLayer = naLayer as ILayer; pLayer.Name = m_NAContext.Solver.DisplayName; m_hookHelper.ActiveView.FocusMap.AddLayer(pLayer); if (inputFClass.FeatureCount(null) < 2) { MessageBox.Show("只有一个站点,不能进行路径分析!"); return; } IGPMessages gpMessages = new GPMessagesClass(); //加载站点要素,并设置容差 NetWorkAnalysClass.LoadNANetworkLocations("Stops", inputFClass, m_NAContext, 80); //加载障碍点要素,并设置容差 NetWorkAnalysClass.LoadNANetworkLocations("Barriers", barriesFClass, m_NAContext, 5); INASolver naSolver = m_NAContext.Solver;//创建网络分析对象 try { naSolver.Solve(m_NAContext, gpMessages, null); } catch (Exception ex) { MessageBox.Show("未能找到有效路径" + ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); return; } for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++) { if (m_hookHelper.FocusMap.get_Layer(i).Name == m_NAContext.Solver.DisplayName) { ICompositeLayer pCompositeLayer = m_hookHelper.FocusMap.get_Layer(i) as ICompositeLayer; { for (int t = 0; t < pCompositeLayer.Count; t++) { ILayer pResultLayer = pCompositeLayer.get_Layer(t); if (pResultLayer.Name == "Stops" || pResultLayer.Name == "Barriers") { pResultLayer.Visible = false; continue; } } } } } IGeoDataset geoDataset; IEnvelope envelope; geoDataset = m_NAContext.NAClasses.get_ItemByName("Routes") as IGeoDataset; envelope = geoDataset.Extent; if (!envelope.IsEmpty) { envelope.Expand(1.1, 1.1, true); } m_hookHelper.ActiveView.Extent = envelope; m_hookHelper.ActiveView.Refresh(); }