//not finished public static void BurstFindValves() { // run a FindPath between 2 flags, create a polyline from the results //需要desktop,放弃 /* * INetworkAnalysisExt pNetAnalysisExt; * INetworkAnalysisExtFlags pNetAnalysisExtFlags; * INetworkAnalysisExtBarriers pNetAnalysisExtBarriers; * INetworkAnalysisExtResults pNetAnalysisExtResults; */ string valvelayername = "Water Fixtures"; string waterlinelayername = "Water Lines"; string waternetworkname = "Water_Network"; INetworkCollection pNetworkCollection; IFeatureDataset pFeatureDataSet; IWorkspaceFactory pWSF = new SdeWorkspaceFactoryClass(); IPropertySet pPropset = new PropertySetClass(); IFeatureWorkspace pFeatureWorkspace = pWSF.Open(pPropset, 0) as IFeatureWorkspace; INetwork pNetwork; IGeometricNetwork pGeometricNetwork; pFeatureDataSet = pFeatureWorkspace.OpenFeatureDataset("datasetName"); pNetworkCollection = pFeatureDataSet as INetworkCollection; pGeometricNetwork = pNetworkCollection.get_GeometricNetworkByName("networkname"); pNetwork = pGeometricNetwork.Network; IEdgeFlagDisplay pEdgeFlagDisplay; IFlagDisplay pFlagDisplay; IEdgeFlag pEdgeFlag; INetFlag pNetFlag; //创建一个flag pEdgeFlag = new EdgeFlagClass(); pNetFlag = pEdgeFlag as INetFlag; IFeatureLayer pFeatLayerValves; IFeatureLayer pFeatLayerWaterLines; UID pID = new UIDClass(); }
//解决路径 public void SolvePath(string WeightName) { try { int intEdgeUserClassID; int intEdgeUserID; int intEdgeUserSubID; int intEdgeID; IPoint ipFoundEdgePoint; double dblEdgePercent; ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver; INetwork ipNetwork = m_ipGeometricNetwork.Network; ipNetSolver.SourceNetwork = ipNetwork; INetElements ipNetElements = ipNetwork as INetElements; int intCount = m_ipPoints.PointCount;//这里的points有值吗? //定义一个边线旗数组 IEdgeFlag[] pEdgeFlagList = new EdgeFlagClass[intCount]; for (int i = 0; i < intCount; i++) { INetFlag ipNetFlag = new EdgeFlagClass() as INetFlag; IPoint ipEdgePoint = m_ipPoints.get_Point(i); //查找输入点的最近的边线 m_ipPointToEID.GetNearestEdge(ipEdgePoint, out intEdgeID, out ipFoundEdgePoint, out dblEdgePercent); ipNetElements.QueryIDs(intEdgeID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdgeUserID, out intEdgeUserSubID); ipNetFlag.UserClassID = intEdgeUserClassID; ipNetFlag.UserID = intEdgeUserID; ipNetFlag.UserSubID = intEdgeUserSubID; IEdgeFlag pTemp = (IEdgeFlag)(ipNetFlag as IEdgeFlag); pEdgeFlagList[i] = pTemp; } ipTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList); INetSchema ipNetSchema = ipNetwork as INetSchema; INetWeight ipNetWeight = ipNetSchema.get_WeightByName(WeightName); INetSolverWeights ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights; ipNetSolverWeights.FromToEdgeWeight = ipNetWeight; //开始边线的权重 ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight; //终止边线的权重 object[] vaRes = new object[intCount - 1]; //通过findpath得到边线和交汇点的集合 ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out m_ipEnumNetEID_Junctions, out m_ipEnumNetEID_Edges, intCount - 1, ref vaRes); //计算元素成本 m_dblPathCost = 0; for (int i = 0; i < vaRes.Length; i++) { double m_Va = (double)vaRes[i];//我修改过 m_dblPathCost = m_dblPathCost + m_Va; } m_ipPolyline = null; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
//not finished public static void BurstFindValves() { // run a FindPath between 2 flags, create a polyline from the results //��Ҫdesktop������ /* INetworkAnalysisExt pNetAnalysisExt; INetworkAnalysisExtFlags pNetAnalysisExtFlags; INetworkAnalysisExtBarriers pNetAnalysisExtBarriers; INetworkAnalysisExtResults pNetAnalysisExtResults; */ string valvelayername = "Water Fixtures"; string waterlinelayername = "Water Lines"; string waternetworkname = "Water_Network"; INetworkCollection pNetworkCollection; IFeatureDataset pFeatureDataSet; IWorkspaceFactory pWSF=new SdeWorkspaceFactoryClass(); IPropertySet pPropset=new PropertySetClass(); IFeatureWorkspace pFeatureWorkspace=pWSF.Open(pPropset,0) as IFeatureWorkspace; INetwork pNetwork; IGeometricNetwork pGeometricNetwork; pFeatureDataSet = pFeatureWorkspace.OpenFeatureDataset("datasetName"); pNetworkCollection=pFeatureDataSet as INetworkCollection; pGeometricNetwork=pNetworkCollection.get_GeometricNetworkByName("networkname"); pNetwork=pGeometricNetwork.Network; IEdgeFlagDisplay pEdgeFlagDisplay; IFlagDisplay pFlagDisplay; IEdgeFlag pEdgeFlag; INetFlag pNetFlag; //����һ��flag pEdgeFlag=new EdgeFlagClass(); pNetFlag=pEdgeFlag as INetFlag; IFeatureLayer pFeatLayerValves; IFeatureLayer pFeatLayerWaterLines; UID pID=new UIDClass(); }
public void SolvePath(string WeightName) { int num; ITraceFlowSolver solver = (ITraceFlowSolver) new TraceFlowSolverClass(); INetSolver solver2 = (INetSolver)solver; INetwork network = this.m_ipGeometricNetwork.Network; solver2.SourceNetwork = network; INetElements elements = (INetElements)network; IEdgeFlag[] edgeOrigins = new IEdgeFlag[this.m_ipPoints.PointCount + 1]; for (num = 0; num < this.m_ipPoints.PointCount; num++) { IPoint point; int num2; double num3; int num4; int num5; int num6; INetFlag flag = new EdgeFlagClass(); IPoint inputPoint = this.m_ipPoints.get_Point(num); this.m_ipPointToEID.GetNearestEdge(inputPoint, out num2, out point, out num3); elements.QueryIDs(num2, esriElementType.esriETEdge, out num4, out num5, out num6); flag.UserClassID = num4; flag.UserID = num5; flag.UserSubID = num6; edgeOrigins[num] = (IEdgeFlag)flag; } (solver as ITraceFlowSolverGEN).PutEdgeOrigins(ref edgeOrigins); try { INetSolverWeights weights = (INetSolverWeights)solver; weights.JunctionWeight = this.JunctionWeight; weights.FromToEdgeWeight = this.FromToEdgeWeight; weights.ToFromEdgeWeight = this.ToFromEdgeWeight; } catch { } object[] segmentCosts = new object[this.m_ipPoints.PointCount]; (solver as ITraceFlowSolverGEN).FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out this.m_ipEnumNetEID_Junctions, out this.m_ipEnumNetEID_Edges, this.m_ipPoints.PointCount - 1, ref segmentCosts); this.m_dblPathCost = 0.0; for (num = 0; num < segmentCosts.Length; num++) { this.m_dblPathCost += (double)segmentCosts[num]; } this.m_ipPolyline = null; }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button != 1) { return; } IPoint inPoint = new PointClass(); inPoint = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IMap map = this.m_hookHelper.FocusMap; //查询与点最近的EID IPointToEID pointToEID = new PointToEIDClass(); pointToEID.GeometricNetwork = geometricNetwork; pointToEID.SourceMap = map; pointToEID.SnapTolerance = 10; IPoint outPoint = new PointClass(); int nearestEdgeID = -1; double percent = -1; pointToEID.GetNearestEdge(inPoint, out nearestEdgeID, out outPoint, out percent); if (outPoint == null || outPoint.IsEmpty) { return; } //获取与点最邻近的边 INetElements netElments = geometricNetwork.Network as INetElements; int userClSSID = 0; int userID = 0; int userSubID = 0; netElments.QueryIDs(nearestEdgeID, esriElementType.esriETEdge, out userClSSID, out userID, out userSubID); INetFlag netFlag = new EdgeFlagClass() as INetFlag; netFlag.UserClassID = userClSSID; netFlag.UserID = userID; netFlag.UserSubID = userSubID; //添加管线标识 listEdgeFlag.Add(netFlag as IEdgeFlag); //绘制点所在的边 DrawElement(outPoint); }
public ITraceFlowSolverGEN UTIL_coreTraceSetup() { // get the current network's logical network INetworkAnalysisExt nax = m_utilNetExt as INetworkAnalysisExt; INetwork net = nax.CurrentNetwork.Network; // create a new TraceFlowSolver object and // set the source network for the solve ITraceFlowSolverGEN tfs = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver netSolver = tfs as INetSolver; netSolver.SourceNetwork = net; // get the barriers for the network, using the element barriers and // selection barriers that have been added using the user interface INetworkAnalysisExtBarriers naxBarriers = m_utilNetExt as INetworkAnalysisExtBarriers; INetElementBarriers juncElemBarriers, edgeElemBarriers; naxBarriers.CreateElementBarriers(out juncElemBarriers, out edgeElemBarriers); ISelectionSetBarriers selSetBarriers; naxBarriers.CreateSelectionBarriers(out selSetBarriers); netSolver.set_ElementBarriers(esriElementType.esriETJunction, juncElemBarriers); netSolver.set_ElementBarriers(esriElementType.esriETEdge, edgeElemBarriers); netSolver.SelectionSetBarriers = selSetBarriers; // set up the disabled layers for the network solver // for each feature layer belonging to this network, determine if it is // enabled or disabled; if it's disabled, then notify the network solver for (int i = 0; i < nax.FeatureLayerCount; i++) { IFeatureLayer featureLayer = nax.get_FeatureLayer(i); if (naxBarriers.GetDisabledLayer(featureLayer)) netSolver.DisableElementClass(featureLayer.FeatureClass.FeatureClassID); } INetworkAnalysisExtWeightFilter naxWeightFilter = m_utilNetExt as INetworkAnalysisExtWeightFilter; INetSolverWeightsGEN netSolverWeights = netSolver as INetSolverWeightsGEN; INetSchema netSchema = net as INetSchema; // create the junction weight filter int juncFilterRangeCount = naxWeightFilter.get_FilterRangeCount(esriElementType.esriETJunction); if (juncFilterRangeCount > 0) { INetWeight netWeight = netSchema.get_WeightByName(naxWeightFilter.JunctionWeightFilterName); netSolverWeights.JunctionFilterWeight = netWeight; esriWeightFilterType juncWeightFilterType; bool juncApplyNotOperator; naxWeightFilter.GetFilterType(esriElementType.esriETJunction, out juncWeightFilterType, out juncApplyNotOperator); netSolverWeights.SetFilterType(esriElementType.esriETJunction, juncWeightFilterType, juncApplyNotOperator); object[] juncFromValues = new object[juncFilterRangeCount]; object[] juncToValues = new object[juncFilterRangeCount]; for (int i = 0; i < juncFilterRangeCount; i++) { naxWeightFilter.GetFilterRange(esriElementType.esriETJunction, i, out juncFromValues[i], out juncToValues[i]); } netSolverWeights.SetFilterRanges(esriElementType.esriETJunction, ref juncFromValues, ref juncToValues); } // create the edge weight filters int edgeFilterRangeCount = naxWeightFilter.get_FilterRangeCount(esriElementType.esriETEdge); if (edgeFilterRangeCount > 0) { INetWeight fromToNetWeight = netSchema.get_WeightByName(naxWeightFilter.FromToEdgeWeightFilterName); netSolverWeights.FromToEdgeFilterWeight = fromToNetWeight; INetWeight toFromNetWeight = netSchema.get_WeightByName(naxWeightFilter.ToFromEdgeWeightFilterName); netSolverWeights.ToFromEdgeFilterWeight = toFromNetWeight; esriWeightFilterType edgeWeightFilterType; bool edgeApplyNotOperator; naxWeightFilter.GetFilterType(esriElementType.esriETEdge, out edgeWeightFilterType, out edgeApplyNotOperator); netSolverWeights.SetFilterType(esriElementType.esriETEdge, edgeWeightFilterType, edgeApplyNotOperator); object[] edgeFromValues = new object[edgeFilterRangeCount]; object[] edgeToValues = new object[edgeFilterRangeCount]; for (int i = 0; i < edgeFilterRangeCount; i++) { naxWeightFilter.GetFilterRange(esriElementType.esriETEdge, i, out edgeFromValues[i], out edgeToValues[i]); } netSolverWeights.SetFilterRanges(esriElementType.esriETEdge, ref edgeFromValues, ref edgeToValues); } INetworkAnalysisExtFlags naxFlags = m_utilNetExt as INetworkAnalysisExtFlags; // assign the edge flags to the network solver int edgeFlagCount = naxFlags.EdgeFlagCount; if (edgeFlagCount > 0) { IEdgeFlag[] edgeFlags = new IEdgeFlag[edgeFlagCount]; for (int i = 0; i < edgeFlagCount; i++) { IEdgeFlagDisplay edgeFlagDisplay = naxFlags.get_EdgeFlag(i); IFlagDisplay flagDisplay = edgeFlagDisplay as IFlagDisplay; IEdgeFlag edgeFlag = new EdgeFlagClass(); edgeFlag.Position = Convert.ToSingle(edgeFlagDisplay.Percentage); INetFlag netFlag = edgeFlag as INetFlag; netFlag.UserClassID = flagDisplay.FeatureClassID; netFlag.UserID = flagDisplay.FID; netFlag.UserSubID = flagDisplay.SubID; edgeFlags[i] = edgeFlag; } tfs.PutEdgeOrigins(ref edgeFlags); } // assign the junction flags to the network solver int juncFlagCount = naxFlags.JunctionFlagCount; if (juncFlagCount > 0) { IJunctionFlag[] juncFlags = new IJunctionFlag[juncFlagCount]; for (int i = 0; i < juncFlagCount; i++) { IJunctionFlagDisplay juncFlagDisplay = naxFlags.get_JunctionFlag(i); IFlagDisplay flagDisplay = juncFlagDisplay as IFlagDisplay; IJunctionFlag juncFlag = new JunctionFlagClass(); INetFlag netFlag = juncFlag as INetFlag; netFlag.UserClassID = flagDisplay.FeatureClassID; netFlag.UserID = flagDisplay.FID; netFlag.UserSubID = flagDisplay.SubID; juncFlags[i] = juncFlag; } tfs.PutJunctionOrigins(ref juncFlags); } // set the option for tracing on indeterminate flow ITraceTasks traceTasks = m_utilNetExt as ITraceTasks; tfs.TraceIndeterminateFlow = traceTasks.TraceIndeterminateFlow; return tfs; }
private void SolvePath(string weightName) { //创建ITraceFlowSolverGEN ITraceFlowSolverGEN pTraceFlowSolverGEN = new TraceFlowSolverClass(); INetSolver pNetSolver = pTraceFlowSolverGEN as INetSolver; //初始化用于路径计算的Network INetwork pNetWork = mGeometricNetwork.Network; pNetSolver.SourceNetwork = pNetWork; //获取分析经过的点的个数 int intCount = mPointCollectionNet.PointCount; if (intCount < 1) { return; } INetFlag pNetFlag; //用于存储路径计算得到的边 IEdgeFlag[] pEdgeFlags = new IEdgeFlag[intCount]; IPoint pEdgePoint = new PointClass(); int intEdgeEID; IPoint pFoundEdgePoint; double dblEdgePercent; //用于获取几何网络元素的UserID, UserClassID,UserSubID INetElements pNetElements = pNetWork as INetElements; int intEdgeUserClassID; int intEdgeUserID; int intEdgeUserSubID; for (int i = 0; i < intCount; i++) { pNetFlag = new EdgeFlagClass(); //获取用户点击点 pEdgePoint = mPointCollectionNet.get_Point(i); //获取距离用户点击点最近的边 mPointToEID.GetNearestEdge(pEdgePoint, out intEdgeEID, out pFoundEdgePoint, out dblEdgePercent); if (intEdgeEID <= 0) { continue; } //根据得到的边查询对应的几何网络中的元素UserID, UserClassID,UserSubID pNetElements.QueryIDs(intEdgeEID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdgeUserID, out intEdgeUserSubID); if (intEdgeUserClassID <= 0 || intEdgeUserID <= 0) { continue; } pNetFlag.UserClassID = intEdgeUserClassID; pNetFlag.UserID = intEdgeUserID; pNetFlag.UserSubID = intEdgeUserSubID; pEdgeFlags[i] = pNetFlag as IEdgeFlag; } //设置路径求解的边 pTraceFlowSolverGEN.PutEdgeOrigins(ref pEdgeFlags); //路径计算权重 INetSchema pNetSchema = pNetWork as INetSchema; INetWeight pNetWeight = pNetSchema.get_WeightByName(weightName); if (pNetWeight == null) { return; } //设置权重,这里双向的权重设为一致 INetSolverWeights pNetSolverWeights = pTraceFlowSolverGEN as INetSolverWeights; pNetSolverWeights.ToFromEdgeWeight = pNetWeight; pNetSolverWeights.FromToEdgeWeight = pNetWeight; object[] arrResults = new object[intCount - 1]; //执行路径计算 pTraceFlowSolverGEN.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out mEnumNetEID_Junctions, out mEnumNetEID_Edges, intCount - 1, ref arrResults); //获取路径计算总代价(cost) mdblPathCost = 0; for (int i = 0; i < intCount - 1; i++) { mdblPathCost += (double)arrResults[i]; } }
//���ҷ��� private void BurstFindValves(IFlagDisplay pFlagDisplay) { try { INetwork pNetwork = pGeoNetwork.Network; IFeatureLayer pValveFeatLayer = Utility.FindFeatLayer("Water Fixtures", this); IFeatureLayer pWaterLineFeatLyr = Utility.FindFeatLayer("Water Lines", this); //�õ�EdgeFlag IEdgeFlag pEdgeFlag = new EdgeFlagClass(); INetFlag pNetFlag = pEdgeFlag as INetFlag; pNetFlag.UserClassID = pFlagDisplay.FeatureClassID; pNetFlag.UserID = pFlagDisplay.FID; //��÷��ŵĹ�� IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = "PWF_TYPE_CODE = 1"; IFeatureSelection pValveFeatSelection = pValveFeatLayer as IFeatureSelection; pValveFeatSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false); //������ѡ��ķ���ΪSelectionSetBarriers ISelectionSetBarriers pSelSetBarriers = new SelectionSetBarriersClass(); int FeatClassID = pValveFeatLayer.FeatureClass.FeatureClassID; IEnumIDs pEnumIDs = pValveFeatSelection.SelectionSet.IDs; pEnumIDs.Reset(); int FeatID = pEnumIDs.Next(); while (FeatID > 0) { pSelSetBarriers.Add(FeatClassID, FeatID); FeatID = pEnumIDs.Next(); } //����TraceFlowSolver ITraceFlowSolver pTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolver; INetSolver pNetSolver = pTraceFlowSolver as INetSolver; pNetSolver.SourceNetwork = pNetwork; pNetSolver.SelectionSetBarriers = pSelSetBarriers; pTraceFlowSolver.PutEdgeOrigins(1, ref pEdgeFlag); //�Ӹ��ٹ����л�ý�� IEnumNetEID pResultJenction; IEnumNetEID pResultsEdges; IEnumNetEID ptmpEnumNetEID = null; pTraceFlowSolver.FindFlowEndElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctions, out pResultJenction, out ptmpEnumNetEID); pTraceFlowSolver.FindFlowElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEEdges, out ptmpEnumNetEID, out pResultsEdges); int lEID; int iUserClassID; int iUserID; int iUserSubID; INetElements pNetElements = pGeoNetwork.Network as INetElements; pResultJenction.Reset(); IFeature pFeature; pValveFeatSelection.Clear(); for (int j = 0; j <= pResultJenction.Count - 1; j++) { lEID = pResultJenction.Next(); pNetElements.QueryIDs(lEID, esriElementType.esriETJunction, out iUserClassID, out iUserID, out iUserSubID); pFeature = pValveFeatLayer.FeatureClass.GetFeature(iUserID); pValveFeatSelection.Add(pFeature); // MessageBox.Show(iUserClassID.ToString()+","+iUserID.ToString()+","+iUserSubID.ToString()); } IFeatureSelection pLinesFeatSelection = pWaterLineFeatLyr as IFeatureSelection; pLinesFeatSelection.Clear(); for (int i = 0; i <= pResultsEdges.Count - 1; i++) { lEID = pResultsEdges.Next(); pNetElements.QueryIDs(lEID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID); pFeature = pWaterLineFeatLyr.FeatureClass.GetFeature(iUserID); pLinesFeatSelection.Add(pFeature); } //�����µķ���������Ⱦѡȡ�Ľ�� IMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass(); IRgbColor pRGBColor = new RgbColorClass(); pRGBColor.Red = 12; pRGBColor.Green = 250; pRGBColor.Blue = 233; pMarkerSymbol.Size = 14; pMarkerSymbol.Color = pRGBColor; pValveFeatSelection.SelectionSymbol = pMarkerSymbol as ISymbol; pValveFeatSelection.SelectionColor = pRGBColor as IColor; pValveFeatSelection.SelectionChanged(); IRgbColor pRGBColor2 = new RgbColorClass(); pRGBColor2.Red = 230; pRGBColor2.Green = 230; pRGBColor2.Blue = 0; pLinesFeatSelection.SelectionColor = pRGBColor2; pLinesFeatSelection.SelectionChanged(); axMapControl1.ActiveView.Refresh(); ICursor pCursor = null; pValveFeatSelection.SelectionSet.Search(null, false, out pCursor); IFeatureCursor pFeatCursor = pCursor as IFeatureCursor; IArray pArray = new ArrayClass(); pFeature = pFeatCursor.NextFeature(); while (pFeature != null) { pArray.Add(pFeature); pFeature = pFeatCursor.NextFeature(); } pFeature = pWaterLineFeatLyr.FeatureClass.GetFeature(pFlagDisplay.FID); frmBurstReport frmBurstReport1 = new frmBurstReport(this, pValveFeatLayer, pWaterLineFeatLyr, pArray, pFeature); frmBurstReport1.Show(); } catch (Exception eX) { MessageBox.Show(eX.Message); } }
//解决路径 public void SolvePath(string WeightName) { try { int intEdgeUserClassID; int intEdgeUserID; int intEdgeUserSubID; int intEdgeID; IPoint ipFoundEdgePoint; double dblEdgePercent; ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver; INetwork ipNetwork = m_ipGeometricNetwork.Network; ipNetSolver.SourceNetwork = ipNetwork; INetElements ipNetElements = ipNetwork as INetElements; int intCount = m_ipPoints.PointCount;//这里的points有值吗? //定义一个边线旗数组 IEdgeFlag[] pEdgeFlagList = new EdgeFlagClass[intCount]; for (int i = 0; i < intCount; i++) { INetFlag ipNetFlag = new EdgeFlagClass() as INetFlag; IPoint ipEdgePoint = m_ipPoints.get_Point(i); //查找输入点的最近的边线 m_ipPointToEID.GetNearestEdge(ipEdgePoint, out intEdgeID, out ipFoundEdgePoint, out dblEdgePercent); ipNetElements.QueryIDs(intEdgeID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdgeUserID, out intEdgeUserSubID); ipNetFlag.UserClassID = intEdgeUserClassID; ipNetFlag.UserID = intEdgeUserID; ipNetFlag.UserSubID = intEdgeUserSubID; IEdgeFlag pTemp = (IEdgeFlag)(ipNetFlag as IEdgeFlag); pEdgeFlagList[i] = pTemp; } ipTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList); INetSchema ipNetSchema = ipNetwork as INetSchema; INetWeight ipNetWeight = ipNetSchema.get_WeightByName(WeightName); INetSolverWeights ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights; ipNetSolverWeights.FromToEdgeWeight = ipNetWeight;//开始边线的权重 ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight;//终止边线的权重 object[] vaRes = new object[intCount - 1]; //通过findpath得到边线和交汇点的集合 ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out m_ipEnumNetEID_Junctions, out m_ipEnumNetEID_Edges, intCount - 1, ref vaRes); //计算元素成本 m_dblPathCost = 0; for (int i = 0; i < vaRes.Length; i++) { double m_Va = (double)vaRes[i];//我修改过 m_dblPathCost = m_dblPathCost + m_Va; } m_ipPolyline = null; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private IEdgeFlag CreateRoadEdgeFlagFromRoadFeature(IFeature road, IPoint closestPoint, IPoint foundPoint) { ICurve roadcurve = road.Shape as ICurve; double distanceAlong = 0; double distanceFrom = 0; bool rightSide = false; roadcurve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, closestPoint, true, foundPoint, ref distanceAlong, ref distanceFrom, ref rightSide); double position = distanceAlong/roadcurve.Length; //create flag IEdgeFlag edgeFlag1 = new EdgeFlagClass(); INetFlag netFlag1 = edgeFlag1 as INetFlag; netFlag1.ClientClassID = 0; netFlag1.ClientID = 0; //netFlag1.Label = "StartFlag"; netFlag1.UserClassID = RoadEdge.ObjectClassID; netFlag1.UserID = road.OID; edgeFlag1.Position = float.Parse(position.ToString()); edgeFlag1.TwoWay = true; return edgeFlag1; }
public static List <int> StreamTrace(IGeometricNetwork geometricNetwork, StartFlagEdge edge, List <int> disabledFeatureClassIds, StopperJunctions stoppers, bool isUpStream, int maxFeatureCount, ServerLogger logger) { esriFlowMethod direction = isUpStream ? esriFlowMethod.esriFMUpstream : esriFlowMethod.esriFMDownstream; if (null == geometricNetwork || null == edge || maxFeatureCount <= 0) { return(null); } ITraceFlowSolverGEN traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = geometricNetwork.Network; INetFlag netFlag = new EdgeFlagClass(); netFlag.UserClassID = edge.FeatureClassID; netFlag.UserID = edge.FeatureID; //no idea when to assign -1, when to do 0 netFlag.UserSubID = -1; traceFlowSolver.PutEdgeOrigins(new IEdgeFlag[1] { netFlag as IEdgeFlag }); if (null != disabledFeatureClassIds) { foreach (int il in disabledFeatureClassIds) { if (il > 0) { netSolver.DisableElementClass(il); } } } if (null != stoppers && null != stoppers.Stoppers && stoppers.Stoppers.Length > 0) { INetElementBarriersGEN netBarriersGEN = null; netBarriersGEN = new NetElementBarriersClass() as INetElementBarriersGEN; netBarriersGEN.ElementType = esriElementType.esriETJunction; netBarriersGEN.Network = geometricNetwork.Network; netBarriersGEN.SetBarriers(stoppers.FeatureClassID, stoppers.Stoppers); netSolver.set_ElementBarriers(esriElementType.esriETJunction, netBarriersGEN as INetElementBarriers); } IEnumNetEID junctionEIDs = null; IEnumNetEID edgeEIDs = null; traceFlowSolver.TraceIndeterminateFlow = false; try { traceFlowSolver.FindFlowElements(direction, esriFlowElements.esriFEEdges, out junctionEIDs, out edgeEIDs); if (null != edgeEIDs) { if (edgeEIDs.Count <= maxFeatureCount) { IEIDHelper eidHelper = new EIDHelperClass(); eidHelper.GeometricNetwork = geometricNetwork; eidHelper.ReturnGeometries = false; eidHelper.ReturnFeatures = true; //eidHelper.AddField("FType"); IEnumEIDInfo eidInfos = eidHelper.CreateEnumEIDInfo(edgeEIDs); eidInfos.Reset(); IEIDInfo eidInfo = null; List <int> ftrs = new List <int>(); //IFeature cadFtr = null; //int ftype; while ((eidInfo = eidInfos.Next()) != null) { ftrs.Add(eidInfo.Feature.OID); /*cadFtr = eidInfo.Feature; * if (null != cadFtr.get_Value(edgeTypeId) && int.TryParse(cadFtr.get_Value(edgeTypeId).ToString(), out ftype)) * { * if(460 == ftype || 558 == ftype) * ftrs.Add(cadFtr); * }*/ } return(ftrs); } } } catch (Exception e) { if (null != logger) { logger.LogMessage(ServerLogger.msgType.error, typeof(AOUtilities).Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, ErrorCode, e.Message); } } finally { ReleaseCOMObj(traceFlowSolver); } return(null); }
private bool slovePath() { try { double costLength = 0; m_ipPointToEID = new PointToEIDClass(); m_ipPointToEID.SourceMap = m_HookHelper.ActiveView.FocusMap; m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork; m_ipPointToEID.SnapTolerance = m_HookHelper.ActiveView.Extent.Envelope.Width / 100; INetwork ipNetwork; INetElements ipNetElements; INetFlag ipNetFlag; //IEdgeFlag ipEdgeFlag; IEdgeFlag [] EdgeFlagArray; int pEdgeID; IPoint pLocation; double dblEdgePercent; int iUserClassID, iUserID, iUserSubID; // look up the EID for the current point (this will populate intEdgeID and dblEdgePercent) ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolver; //get the inetsolver interface ipNetSolver = ipTraceFlowSolver as INetSolver; ipNetwork = m_ipGeometricNetwork.Network; //set the net solver's source network ipNetSolver.SourceNetwork = ipNetwork; //make edge flags from the points //the INetElements interface is needed to get UserID, UserClassID, //and UserSubID from an element id EdgeFlagArray = new IEdgeFlag[mPointArray.PointCount]; ipNetElements = ipNetwork as INetElements; for (int ii = 0; ii < mPointArray.PointCount; ii++) { ipNetFlag = new EdgeFlagClass(); point = mPointArray.get_Point(ii); m_ipPointToEID.GetNearestEdge(point, out pEdgeID, out pLocation, out dblEdgePercent); //iUserClassID是featureclass ID,userID是objectID,userSubID ipNetElements.QueryIDs(pEdgeID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID); ipNetFlag.UserClassID = iUserClassID; ipNetFlag.UserID = iUserID; ipNetFlag.UserSubID = iUserSubID; EdgeFlagArray[ii] = ipNetFlag as IEdgeFlag; //MessageBox.Show(iUserID.ToString()); } //添加到TraceFlowSolver中 ITraceFlowSolverGEN pTFSolverGEN = ipTraceFlowSolver as ITraceFlowSolverGEN; pTFSolverGEN.PutEdgeOrigins(ref EdgeFlagArray); //get the INetSchema interface INetSchema ipNetSchema = ipNetwork as INetSchema; INetWeight ipNetWeight = ipNetSchema.get_Weight(0); //MessageBox.Show(ipNetWeight.WeightName); INetSolverWeights ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights; //来回使用同一个权重 ipNetSolverWeights.FromToEdgeWeight = ipNetWeight; ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight; object [] totalCost = new object[mPointArray.PointCount - 1]; pTFSolverGEN.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out m_ipEnumNetEID_Junctions, out m_ipEnumNetEID_Edges, mPointArray.PointCount - 1, ref totalCost); //MessageBox.Show(totalCost[0].ToString()); for (int ii = 0; ii < totalCost.Length; ii++) { costLength += (double)(totalCost[ii]); } pStatusBar.Panels[0].Text = "水管长度:" + costLength.ToString(); return(true); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } }
private bool slovePath() { try { double costLength=0; m_ipPointToEID = new PointToEIDClass(); m_ipPointToEID.SourceMap=m_HookHelper.ActiveView.FocusMap; m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork; m_ipPointToEID.SnapTolerance=m_HookHelper.ActiveView.Extent.Envelope.Width/100; INetwork ipNetwork; INetElements ipNetElements; INetFlag ipNetFlag; //IEdgeFlag ipEdgeFlag; IEdgeFlag [] EdgeFlagArray; int pEdgeID; IPoint pLocation; double dblEdgePercent; int iUserClassID,iUserID,iUserSubID; // look up the EID for the current point (this will populate intEdgeID and dblEdgePercent) ipTraceFlowSolver=new TraceFlowSolverClass() as ITraceFlowSolver; //get the inetsolver interface ipNetSolver=ipTraceFlowSolver as INetSolver; ipNetwork=m_ipGeometricNetwork.Network; //set the net solver's source network ipNetSolver.SourceNetwork=ipNetwork; //make edge flags from the points //the INetElements interface is needed to get UserID, UserClassID, //and UserSubID from an element id EdgeFlagArray=new IEdgeFlag[mPointArray.PointCount]; ipNetElements = ipNetwork as INetElements; for(int ii=0;ii<mPointArray.PointCount;ii++) { ipNetFlag = new EdgeFlagClass(); point=mPointArray.get_Point(ii); m_ipPointToEID.GetNearestEdge(point,out pEdgeID,out pLocation,out dblEdgePercent); //iUserClassID��featureclass ID,userID��objectID,userSubID ipNetElements.QueryIDs(pEdgeID,esriElementType.esriETEdge,out iUserClassID,out iUserID,out iUserSubID); ipNetFlag.UserClassID=iUserClassID; ipNetFlag.UserID=iUserID; ipNetFlag.UserSubID=iUserSubID; EdgeFlagArray[ii]=ipNetFlag as IEdgeFlag; //MessageBox.Show(iUserID.ToString()); } //��ӵ�TraceFlowSolver�� ITraceFlowSolverGEN pTFSolverGEN=ipTraceFlowSolver as ITraceFlowSolverGEN; pTFSolverGEN.PutEdgeOrigins(ref EdgeFlagArray); //get the INetSchema interface INetSchema ipNetSchema = ipNetwork as INetSchema; INetWeight ipNetWeight = ipNetSchema.get_Weight(0); //MessageBox.Show(ipNetWeight.WeightName); INetSolverWeights ipNetSolverWeights=ipTraceFlowSolver as INetSolverWeights; //����ʹ��ͬһ��Ȩ�� ipNetSolverWeights.FromToEdgeWeight=ipNetWeight; ipNetSolverWeights.ToFromEdgeWeight=ipNetWeight; object [] totalCost=new object[mPointArray.PointCount-1]; pTFSolverGEN.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out m_ipEnumNetEID_Junctions, out m_ipEnumNetEID_Edges, mPointArray.PointCount-1,ref totalCost); //MessageBox.Show(totalCost[0].ToString()); for(int ii=0;ii<totalCost.Length;ii++){ costLength+=(double)(totalCost[ii]); } pStatusBar.Panels[0].Text="ˮ�ܳ���:"+costLength.ToString(); return true; } catch(Exception e){ MessageBox.Show(e.Message); return false; } }
/// <summary> /// Set Flags Geometric Network /// </summary> protected void SetFlagsGeometricNetwork() { //// edge Flags List <INetFlag> edgeFlagList = new List <INetFlag>(); this.flagNotFound = new List <IGeometry>(); if (this.EdgeFlags.Count > 0) { foreach (IPoint point in this.EdgeFlags) { int eid = this.GetEIDFromPoint(this.Tolerance, point, esriElementType.esriETEdge); if (eid < 1) { this.flagNotFound.Add(point); continue; } INetElements netElements = this.geometricNetwork.Network as INetElements; int featureClassID, featureID, subID; netElements.QueryIDs(eid, esriElementType.esriETEdge, out featureClassID, out featureID, out subID); INetFlag netFlag = new EdgeFlagClass(); netFlag.UserClassID = featureClassID; netFlag.UserID = featureID; netFlag.UserSubID = subID; edgeFlagList.Add(netFlag); } this.edgeFlags = new IEdgeFlag[edgeFlagList.Count]; edgeFlagList.Each((i, index) => { this.edgeFlags[index] = i as IEdgeFlag; }); } //// junction Flags List <INetFlag> junctionFlagList = new List <INetFlag>(); if (this.JunctionFlags.Count > 0) { foreach (IPoint point in this.JunctionFlags) { int eid = this.GetEIDFromPoint(this.Tolerance, point, esriElementType.esriETJunction); if (eid < 1) { this.flagNotFound.Add(point); continue; } INetElements netElements = this.geometricNetwork.Network as INetElements; int featureClassID, featureID, subID; netElements.QueryIDs(eid, esriElementType.esriETJunction, out featureClassID, out featureID, out subID); INetFlag netFlag = new JunctionFlagClass(); netFlag.UserClassID = featureClassID; netFlag.UserID = featureID; netFlag.UserSubID = subID; junctionFlagList.Add(netFlag); } this.junctionFlags = new IJunctionFlag[junctionFlagList.Count]; junctionFlagList.Each((i, index) => { this.junctionFlags[index] = i as JunctionFlag; }); } }
public ITraceFlowSolverGEN UTIL_coreTraceSetup() { // get the current network's logical network INetworkAnalysisExt nax = m_utilNetExt as INetworkAnalysisExt; INetwork net = nax.CurrentNetwork.Network; // create a new TraceFlowSolver object and // set the source network for the solve ITraceFlowSolverGEN tfs = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver netSolver = tfs as INetSolver; netSolver.SourceNetwork = net; // get the barriers for the network, using the element barriers and // selection barriers that have been added using the user interface INetworkAnalysisExtBarriers naxBarriers = m_utilNetExt as INetworkAnalysisExtBarriers; INetElementBarriers juncElemBarriers, edgeElemBarriers; naxBarriers.CreateElementBarriers(out juncElemBarriers, out edgeElemBarriers); ISelectionSetBarriers selSetBarriers; naxBarriers.CreateSelectionBarriers(out selSetBarriers); netSolver.set_ElementBarriers(esriElementType.esriETJunction, juncElemBarriers); netSolver.set_ElementBarriers(esriElementType.esriETEdge, edgeElemBarriers); netSolver.SelectionSetBarriers = selSetBarriers; // set up the disabled layers for the network solver // for each feature layer belonging to this network, determine if it is // enabled or disabled; if it's disabled, then notify the network solver for (int i = 0; i < nax.FeatureLayerCount; i++) { IFeatureLayer featureLayer = nax.get_FeatureLayer(i); if (naxBarriers.GetDisabledLayer(featureLayer)) { netSolver.DisableElementClass(featureLayer.FeatureClass.FeatureClassID); } } INetworkAnalysisExtWeightFilter naxWeightFilter = m_utilNetExt as INetworkAnalysisExtWeightFilter; INetSolverWeightsGEN netSolverWeights = netSolver as INetSolverWeightsGEN; INetSchema netSchema = net as INetSchema; // create the junction weight filter int juncFilterRangeCount = naxWeightFilter.get_FilterRangeCount(esriElementType.esriETJunction); if (juncFilterRangeCount > 0) { INetWeight netWeight = netSchema.get_WeightByName(naxWeightFilter.JunctionWeightFilterName); netSolverWeights.JunctionFilterWeight = netWeight; esriWeightFilterType juncWeightFilterType; bool juncApplyNotOperator; naxWeightFilter.GetFilterType(esriElementType.esriETJunction, out juncWeightFilterType, out juncApplyNotOperator); netSolverWeights.SetFilterType(esriElementType.esriETJunction, juncWeightFilterType, juncApplyNotOperator); object[] juncFromValues = new object[juncFilterRangeCount]; object[] juncToValues = new object[juncFilterRangeCount]; for (int i = 0; i < juncFilterRangeCount; i++) { naxWeightFilter.GetFilterRange(esriElementType.esriETJunction, i, out juncFromValues[i], out juncToValues[i]); } netSolverWeights.SetFilterRanges(esriElementType.esriETJunction, ref juncFromValues, ref juncToValues); } // create the edge weight filters int edgeFilterRangeCount = naxWeightFilter.get_FilterRangeCount(esriElementType.esriETEdge); if (edgeFilterRangeCount > 0) { INetWeight fromToNetWeight = netSchema.get_WeightByName(naxWeightFilter.FromToEdgeWeightFilterName); netSolverWeights.FromToEdgeFilterWeight = fromToNetWeight; INetWeight toFromNetWeight = netSchema.get_WeightByName(naxWeightFilter.ToFromEdgeWeightFilterName); netSolverWeights.ToFromEdgeFilterWeight = toFromNetWeight; esriWeightFilterType edgeWeightFilterType; bool edgeApplyNotOperator; naxWeightFilter.GetFilterType(esriElementType.esriETEdge, out edgeWeightFilterType, out edgeApplyNotOperator); netSolverWeights.SetFilterType(esriElementType.esriETEdge, edgeWeightFilterType, edgeApplyNotOperator); object[] edgeFromValues = new object[edgeFilterRangeCount]; object[] edgeToValues = new object[edgeFilterRangeCount]; for (int i = 0; i < edgeFilterRangeCount; i++) { naxWeightFilter.GetFilterRange(esriElementType.esriETEdge, i, out edgeFromValues[i], out edgeToValues[i]); } netSolverWeights.SetFilterRanges(esriElementType.esriETEdge, ref edgeFromValues, ref edgeToValues); } INetworkAnalysisExtFlags naxFlags = m_utilNetExt as INetworkAnalysisExtFlags; // assign the edge flags to the network solver int edgeFlagCount = naxFlags.EdgeFlagCount; if (edgeFlagCount > 0) { IEdgeFlag[] edgeFlags = new IEdgeFlag[edgeFlagCount]; for (int i = 0; i < edgeFlagCount; i++) { IEdgeFlagDisplay edgeFlagDisplay = naxFlags.get_EdgeFlag(i); IFlagDisplay flagDisplay = edgeFlagDisplay as IFlagDisplay; IEdgeFlag edgeFlag = new EdgeFlagClass(); edgeFlag.Position = Convert.ToSingle(edgeFlagDisplay.Percentage); INetFlag netFlag = edgeFlag as INetFlag; netFlag.UserClassID = flagDisplay.FeatureClassID; netFlag.UserID = flagDisplay.FID; netFlag.UserSubID = flagDisplay.SubID; edgeFlags[i] = edgeFlag; } tfs.PutEdgeOrigins(ref edgeFlags); } // assign the junction flags to the network solver int juncFlagCount = naxFlags.JunctionFlagCount; if (juncFlagCount > 0) { IJunctionFlag[] juncFlags = new IJunctionFlag[juncFlagCount]; for (int i = 0; i < juncFlagCount; i++) { IJunctionFlagDisplay juncFlagDisplay = naxFlags.get_JunctionFlag(i); IFlagDisplay flagDisplay = juncFlagDisplay as IFlagDisplay; IJunctionFlag juncFlag = new JunctionFlagClass(); INetFlag netFlag = juncFlag as INetFlag; netFlag.UserClassID = flagDisplay.FeatureClassID; netFlag.UserID = flagDisplay.FID; netFlag.UserSubID = flagDisplay.SubID; juncFlags[i] = juncFlag; } tfs.PutJunctionOrigins(ref juncFlags); } // set the option for tracing on indeterminate flow ITraceTasks traceTasks = m_utilNetExt as ITraceTasks; tfs.TraceIndeterminateFlow = traceTasks.TraceIndeterminateFlow; return(tfs); }
//解决路径 public void SolvePath(string WeightName) { try { int intEdgeUserClassID; int intEdgeUserID; int intEdgeUserSubID; int intEdgeID; IPoint ipFoundEdgePoint; double dblEdgePercent; //定义追踪线 ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver; //ipNetSolver.SelectionSetBarriers INetwork ipNetwork = m_ipGeometricNetwork.Network; ipNetSolver.SourceNetwork = ipNetwork; INetElements ipNetElements = ipNetwork as INetElements; int intCount = m_ipPoints.PointCount; //定义一个边线旗数组,各边线与输入点最近 IEdgeFlag[] pEdgeFlagList = new EdgeFlagClass[intCount]; for (int i = 0; i < intCount; i++) { INetFlag ipNetFlag = new EdgeFlagClass() as INetFlag; IPoint ipEdgePoint = m_ipPoints.get_Point(i); //查找输入点的最近的边线 m_ipPointToEID.GetNearestEdge(ipEdgePoint, out intEdgeID, out ipFoundEdgePoint, out dblEdgePercent); ipNetElements.QueryIDs(intEdgeID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdgeUserID, out intEdgeUserSubID); ipNetFlag.UserClassID = intEdgeUserClassID; ipNetFlag.UserID = intEdgeUserID; ipNetFlag.UserSubID = intEdgeUserSubID; IEdgeFlag pTemp = (IEdgeFlag)(ipNetFlag as IEdgeFlag); pEdgeFlagList[i] = pTemp; } IFeatureClassContainer ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer; IFeatureClass ipFeatureClass; int count = ipFeatureClassContainer.ClassCount; if (barrierflag == 1) { for (int i = 0; i < count; i++) { ipFeatureClass = ipFeatureClassContainer.get_Class(i); INetElementBarriers inetelementbarriers; if (i == 0) { inetelementbarriers = setbarriers(ipFeatureClass, barrierarray1, ipNetwork); if(inetelementbarriers!=null) ipNetSolver.set_ElementBarriers(esriElementType.esriETEdge, inetelementbarriers); } if (i == 1) { inetelementbarriers = setbarriers(ipFeatureClass, barrierarray2, ipNetwork); if(inetelementbarriers!=null) ipNetSolver.set_ElementBarriers(esriElementType.esriETEdge, inetelementbarriers); } } } ipTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList); INetSchema ipNetSchema = ipNetwork as INetSchema; INetWeight ipNetWeight = ipNetSchema.get_WeightByName(WeightName); INetSolverWeights ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights; ipNetSolverWeights.FromToEdgeWeight = ipNetWeight;//开始边线的权重 ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight;//终止边线的权重 object[] vaRes = new object[intCount - 1]; //通过findpath得到边线和交汇点的集合 ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out m_ipEnumNetEID_Junctions, out m_ipEnumNetEID_Edges, intCount - 1, ref vaRes); //计算成本 m_dblPathCost = 0; for (int i = 0; i < vaRes.Length; i++) { double m_Va = (double)vaRes[i]; m_dblPathCost = m_dblPathCost + m_Va; } m_ipPolyline = null; } catch (Exception ex) { Console.WriteLine(ex); } }
/// <summary> /// 求解最短路径 /// </summary> /// <param name="_pMap"></param> /// <param name="_pGeometricNetwork"></param> /// <param name="_pWeightName"></param> /// <param name="_pPoints"></param> /// <param name="_pDist"></param> /// <param name="_pPolyline"></param> /// <param name="_pPathCost"></param> public void SolvePath(IMap _pMap, IGeometricNetwork _pGeometricNetwork, string _pWeightName, IPointCollection _pPoints, double _pDist, ref IPolyline _pPolyline, ref double _pPathCost) { try { // 这4个参数其实就是一个定位Element的指标 int intEdgeUserClassID; int intEdgeUserID; int intEdgeUserSubID; int intEdgeID; IPoint pFoundEdgePoint; double dblEdgePercent; ITraceFlowSolverGEN pTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver pNetSolver = pTraceFlowSolver as INetSolver; //操作是针对逻辑网络的,INetwork是逻辑网络 INetwork pNetwork = _pGeometricNetwork.Network; pNetSolver.SourceNetwork = pNetwork; INetElements pNetElements = pNetwork as INetElements; int pCount = _pPoints.PointCount; //定义一个边线旗数组 IEdgeFlag[] pEdgeFlagList = new EdgeFlagClass[pCount]; IPointToEID pPointToEID = new PointToEIDClass(); pPointToEID.SourceMap = _pMap; pPointToEID.GeometricNetwork = _pGeometricNetwork; pPointToEID.SnapTolerance = _pDist; for (int i = 0; i < pCount; i++) { INetFlag pNetFlag = new EdgeFlagClass() as INetFlag; IPoint pEdgePoint = _pPoints.get_Point(i); //查找输入点的最近的边线 pPointToEID.GetNearestEdge(pEdgePoint, out intEdgeID, out pFoundEdgePoint, out dblEdgePercent); pNetElements.QueryIDs(intEdgeID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdgeUserID, out intEdgeUserSubID); pNetFlag.UserClassID = intEdgeUserClassID; pNetFlag.UserID = intEdgeUserID; pNetFlag.UserSubID = intEdgeUserSubID; IEdgeFlag pTemp = (IEdgeFlag)(pNetFlag as IEdgeFlag); pEdgeFlagList[i] = pTemp; } pTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList); INetSchema pNetSchema = pNetwork as INetSchema; INetWeight pNetWeight = pNetSchema.get_WeightByName(_pWeightName); INetSolverWeightsGEN pNetSolverWeights = pTraceFlowSolver as INetSolverWeightsGEN; pNetSolverWeights.FromToEdgeWeight = pNetWeight;//开始边线的权重 pNetSolverWeights.ToFromEdgeWeight = pNetWeight;//终止边线的权重 object[] pRes = new object[pCount - 1]; //通过FindPath得到边线和交汇点的集合 IEnumNetEID pEnumNetEID_Junctions; IEnumNetEID pEnumNetEID_Edges; pTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out pEnumNetEID_Junctions, out pEnumNetEID_Edges, pCount - 1, ref pRes); //计算元素成本 _pPathCost = 0; for (int i = 0; i < pRes.Length; i++) { double m_Va = (double)pRes[i]; _pPathCost = _pPathCost + m_Va; } IGeometryCollection pNewGeometryColl = _pPolyline as IGeometryCollection;//QI ISpatialReference pSpatialReference = _pMap.SpatialReference; IEIDHelper pEIDHelper = new EIDHelperClass(); pEIDHelper.GeometricNetwork = _pGeometricNetwork; pEIDHelper.OutputSpatialReference = pSpatialReference; pEIDHelper.ReturnGeometries = true; IEnumEIDInfo pEnumEIDInfo = pEIDHelper.CreateEnumEIDInfo(pEnumNetEID_Edges); int Count = pEnumEIDInfo.Count; pEnumEIDInfo.Reset(); for (int i = 0; i < Count; i++) { IEIDInfo pEIDInfo = pEnumEIDInfo.Next(); IGeometry pGeometry = pEIDInfo.Geometry; pNewGeometryColl.AddGeometryCollection(pGeometry as IGeometryCollection); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }