private void ClearNet_Click(object sender, EventArgs e) { axMapControl1.CurrentTool = null; try { //string name =path + "\\WHU_StudentQuery.mdb"; //string name = NetWorkAnalysClass.getPath(path) + "\\ArcEngineDemo\\WHU_StudentQuery.mdb"; string name = NetWorkAnalysClass.getPath(path) + "\\Data\\TestNet.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); } 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(); }
public void SetNetWorkDataset_Layers() { View.SetNetWorkDataStatusText(false); if (NetWorkAnalysClass.SearchForNetWorkData(NetWorkAnalysClass.OpenNetWorkDataType.Layers)) { View.ShowMessage("网络数据集获取成功"); View.SetNetWorkDataStatusText(true); } else { View.ShowError("未找到合适的网络数据集!"); } }
/// <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"; string name = NetWorkAnalysClass.getPath(path) + "\\Data\\TestNet.gdb"; pFWorkspace = NetWorkAnalysClass.OpenWorkspace(name) as IFeatureWorkspace; barriesFClass = pFWorkspace.OpenFeatureClass("Barries"); if (barriesFClass.FeatureCount(null) > 0) { ITable pTable = barriesFClass as ITable; pTable.DeleteSearchedRows(null); } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add AddNetBarriesTool.OnMouseDown implementation try { IPoint pStopsPoint = new PointClass(); pStopsPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IFeature newPointFeature = barriesFClass.CreateFeature(); try { newPointFeature.Shape = pStopsPoint; } catch { IGeometry pGeo = pStopsPoint; IZAware pZAware = pGeo as IZAware; pZAware.ZAware = false; newPointFeature.Shape = pGeo; } newPointFeature.Store(); IGraphicsContainer pGrap = m_hookHelper.ActiveView as IGraphicsContainer; IColor pColor; IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 255; pRgbColor.Green = 255; pRgbColor.Blue = 255; pColor = pRgbColor as IColor; IPictureMarkerSymbol pms = new PictureMarkerSymbolClass(); pms.BitmapTransparencyColor = pColor; //添加自定义障碍点图片 pms.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, NetWorkAnalysClass.getPath(path) + "\\data\\Img\\barries.bmp"); pms.Size = 18; IMarkerElement pMarkerEle = new MarkerElementClass(); pMarkerEle.Symbol = pms as IMarkerSymbol; pStopsPoint.SpatialReference = m_hookHelper.ActiveView.FocusMap.SpatialReference; IElement pEle = pMarkerEle as IElement; pEle.Geometry = pStopsPoint; pGrap.AddElement(pEle, 1); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch { MessageBox.Show("障碍点添加失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
public void SetNetWorkDataset_GDBFolder() { View.SetNetWorkDataStatusText(false); var outTuple = new Tuple <string, string>("", ""); NetWorkAnalysClass.OutSourceGDBDatabasePath = View.OutGDBFolder; if (NetWorkAnalysClass.SearchForNetWorkData(NetWorkAnalysClass.OpenNetWorkDataType.GDBFolder, outTuple)) { View.ShowMessage("网络数据集获取成功"); View.DataBaseName = outTuple.Item1; View.DataSetname = outTuple.Item2; View.SetNetWorkDataStatusText(true); } else { View.ShowError("未找到合适的网络数据集!"); } }
/// <summary> /// Occurs when this tool is created /// </summary> /// <param name="hook">Instance of the application</param> public override void OnCreate(object hook) { try { m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = hook; if (m_hookHelper.ActiveView == null) { m_hookHelper = null; } } catch { m_hookHelper = null; } if (m_hookHelper == null) { base.m_enabled = false; } else { base.m_enabled = true; } // TODO: Add other initialization code pFWorkspace = NetWorkAnalysClass.MemoryWorkspace as IFeatureWorkspace; //如果未建立FeatureClass 则创建 try { inputFClass = pFWorkspace.OpenFeatureClass("Stops"); } catch (Exception e) { inputFClass = NetWorkAnalysClass.CreateFeatureClass(pFWorkspace, "Stops"); } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add ShortPathSolveCommand.OnClick implementation IFeatureWorkspace pFWorkspace = NetWorkAnalysClass.MemoryWorkspace as IFeatureWorkspace; //networkDataset = NetWorkAnalysClass.OpenPathNetworkDataset("RouteNetwork", "BaseData"); networkDataset = NetWorkAnalysClass.NetWorkDataSet; //通过网络数据集创建网络分析上下文 m_NAContext = NetWorkAnalysClass.CreatePathSolverContext(networkDataset); //打开要素数据集 //如果这两个报异常 说明FeatureClass为空 新建 try { inputFClass = pFWorkspace.OpenFeatureClass("Stops"); } catch (Exception e) { inputFClass = NetWorkAnalysClass.CreateFeatureClass(pFWorkspace, "Stops"); } try { barriesFClass = pFWorkspace.OpenFeatureClass("Barries"); } catch (Exception e) { barriesFClass = NetWorkAnalysClass.CreateFeatureClass(pFWorkspace, "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(); }