/// <summary> /// Рассчитать затраты на проведение данного КПД по одной грани графа. /// </summary> /// <param name="project">Свойства проекта.</param> /// <param name="edge">Грань, вдоль которой проведён данный КПД.</param> /// <returns>Значение выбранных затрат на проведение КПД.</returns> public double GetCost(Project project, TopologyEdge edge) { try { switch (ConnectionType) { case ConnectionType.Wired: return(GetCost(project, 1 + edge.Weights[ConnectionType] / 10)); case ConnectionType.Wireless: return(0); case ConnectionType.None: return(edge.Weights[ConnectionType]); default: return(TopologyFitness.UNACCEPTABLE); } } catch (Exception ex) { Console.WriteLine("DataChannel GetCost failed! {0}", ex.Message); return(TopologyFitness.UNACCEPTABLE); } }
public void FindClosestElement() { using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb")))) using (Topology topology = geodatabase.OpenDataset <Topology>("Backcountry_Topology")) { // Build a topology graph using the extent of the topology dataset. topology.BuildGraph(topology.GetExtent(), (topologyGraph) => { MapPoint queryPointViaCampsites12 = null; using (Feature campsites12 = GetFeature(geodatabase, "Campsites", 12)) { queryPointViaCampsites12 = campsites12.GetShape() as MapPoint; } double searchRadius = 1.0; TopologyElement topologyElementViaCampsites12 = topologyGraph.FindClosestElement <TopologyElement>(queryPointViaCampsites12, searchRadius); System.Diagnostics.Debug.Assert(topologyElementViaCampsites12 != null, "There should be a topology element corresponding to 'queryPointViaCampsites12' within the 'searchRadius' units."); IReadOnlyList <FeatureInfo> parentFeatures = topologyElementViaCampsites12.GetParentFeatures(); Console.WriteLine("The parent features that spawn 'topologyElementViaCampsites12' are:"); foreach (FeatureInfo parentFeature in parentFeatures) { Console.WriteLine($"\t{parentFeature.FeatureClassName}; OID: {parentFeature.ObjectID}"); } TopologyNode topologyNodeViaCampsites12 = topologyGraph.FindClosestElement <TopologyNode>(queryPointViaCampsites12, searchRadius); if (topologyNodeViaCampsites12 != null) { // There exists a TopologyNode nearest to the query point within searchRadius units. } TopologyEdge topologyEdgeViaCampsites12 = topologyGraph.FindClosestElement <TopologyEdge>(queryPointViaCampsites12, searchRadius); if (topologyEdgeViaCampsites12 != null) { // There exists a TopologyEdge nearest to the query point within searchRadius units. } }); } }