/// <summary> /// 设置障碍点 /// </summary> /// <param name="pNetSolver"></param> /// <param name="breakPoints"></param> /// <param name="pGeometricNet"></param> /// <param name="pDisc"></param> private void SetBarries(INetSolver pNetSolver, List <IPoint> breakPoints, IGeometricNetwork pGeometricNet, double pDisc) { INetwork pNetwork = pGeometricNet.Network; INetElements pNetElements = pNetwork as INetElements; IPointToEID pPointToEID = new PointToEIDClass(); pPointToEID.GeometricNetwork = pGeometricNet; pPointToEID.SnapTolerance = pDisc; ISelectionSetBarriers barriers = new SelectionSetBarriersClass(); foreach (var point in breakPoints) { //寻找障碍点最近的线要素,从而添加爆管线 int nearEdgeID; IPoint outIpoint; double precent; pPointToEID.GetNearestEdge(point, out nearEdgeID, out outIpoint, out precent); int userClassID; int userID; int userSubID; //查询相关ID pNetElements.QueryIDs(nearEdgeID, esriElementType.esriETJunction, out userClassID, out userID, out userSubID); //添加障碍点 barriers.Add(userClassID, userID); } pNetSolver.SelectionSetBarriers = barriers; }
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); // IPointToEID pointToEID = new PointToEIDClass(); pointToEID.GeometricNetwork = geometricNetwork; pointToEID.SourceMap = m_hookHelper.FocusMap; pointToEID.SnapTolerance = 10; // int nearestEID = -1; double percent = -1; IPoint outPoint = new PointClass(); pointToEID.GetNearestEdge(inPoint, out nearestEID, out outPoint, out percent); // if (outPoint.IsEmpty || outPoint == null) { return; } edgeBarrierEIDs.Add(nearestEID); //绘制图形 DrawElement(outPoint); }
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 static void CalculateFlowAccumAtLocation(List<FlowLayerDetails> sumFlowAcc, IApplication app, double snapTol) { IMap pMap = null; IFeatureLayer pFLayer = null; IFeatureCursor pFCursor = null; IFeature pFeature = null; IPointToEID pPointToEid = null; string retAcc = ""; int lSumFieldLoc; int lEID; IPoint pSnappedPoint = null; INetElements pNetElements = null; try { if (app == null) return; pMap = ((app.Document as IMxDocument).FocusMap); if (pMap == null) return; if (sumFlowAcc == null) MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20c")); if (sumFlowAcc.Count == 0) MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20c")); bool flowCalced = false; foreach (FlowLayerDetails sumAcc in sumFlowAcc) { if (flowCalced == true) break; bool boolFoundAsLayer = true; pFLayer = Globals.FindLayer(app, sumAcc.LayerName, ref boolFoundAsLayer) as IFeatureLayer; if (pFLayer == null) { //MessageBox.Show(sumAcc.LayerName + " feature layer not found.\nAny selected features in this layer will be analyzed for acculmuation."); continue; } if (pFLayer.FeatureClass == null) { MessageBox.Show(sumAcc.LayerName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20a")); continue; } lSumFieldLoc = pFLayer.FeatureClass.Fields.FindField(sumAcc.SumFlowField); if (lSumFieldLoc == -1) { MessageBox.Show(sumAcc.LayerName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20b") + sumAcc.SumFlowField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20e")); return; } lEID = -1; //Convert pixcel search distance to real world (map units) //dRWSearchTolerance = c_iSearchTolerance; //Find the closest network junction element to the user specified point pPointToEid = new PointToEIDClass(); pPointToEid.GeometricNetwork = ((INetworkClass)pFLayer.FeatureClass).GeometricNetwork; pPointToEid.SourceMap = pMap; pPointToEid.SnapTolerance = snapTol; bool bTest = false; if (pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline || pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryLine) { double dblPercAlong = 0; pPointToEid.GetNearestEdge((app.Document as IMxDocument).CurrentLocation, out lEID, out pSnappedPoint, out dblPercAlong); if (pSnappedPoint == null) continue; if (lEID == 0) continue; //Get the complete id for the network element pNetElements = (((INetworkClass)pFLayer.FeatureClass).GeometricNetwork.Network) as INetElements; bTest = pNetElements.IsValidElement(lEID, esriElementType.esriETEdge); pFeature = Globals.GetFeatureByEID(lEID, ((INetworkClass)pFLayer.FeatureClass).GeometricNetwork, pMap, esriElementType.esriETEdge); } else if (pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint) { pPointToEid.GetNearestJunction((app.Document as IMxDocument).CurrentLocation, out lEID, out pSnappedPoint); if (pSnappedPoint == null) continue; if (lEID == 0) continue; //Get the complete id for the network element pNetElements = (((INetworkClass)pFLayer.FeatureClass).GeometricNetwork.Network) as INetElements; bTest = pNetElements.IsValidElement(lEID, esriElementType.esriETJunction); pFeature = Globals.GetFeatureByEID(lEID, ((INetworkClass)pFLayer.FeatureClass).GeometricNetwork, pMap, esriElementType.esriETJunction); } if (bTest && pFeature != null) { retAcc = Globals.ReturnAccumulation(ref app, ref pFeature, sumAcc.WeightName, sumAcc.FlowDirection); if (Globals.IsNumeric(retAcc)) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_20b") + pFeature.OID + A4LGSharedFunctions.Localizer.GetString("In") + pFLayer.Name + A4LGSharedFunctions.Localizer.GetString("Is") + retAcc + "."); //pFeature.set_Value(lSumFieldLoc, retAcc); //pFeature.Store(); } } flowCalced =true; } if (flowCalced == false) MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20f")); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_20a") + "\n" + ex.Message); } finally { pMap = null; pFLayer = null; if (pFCursor != null) Marshal.ReleaseComObject(pFCursor); pFCursor = null; pFeature = null; pSnappedPoint = null; pNetElements = null; } }
//Ϊ�����������ñߵ�Flag private void BurstSetEdgeFlag(IPoint pPoint) { // try { INetElements pNetElements = pGeoNetwork.Network as INetElements; IPointToEID pPtToEID = new PointToEIDClass(); IPoint pNewPt; int iUserClassID; int iUserID; int iUserSubID; double dPercent; int eid; pPtToEID.SourceMap = axMapControl1.ActiveView.FocusMap; pPtToEID.GeometricNetwork = pGeoNetwork; pPtToEID.SnapTolerance = axMapControl1.ActiveView.Extent.Envelope.Width / 100; pPtToEID.GetNearestEdge(pPoint, out eid, out pNewPt, out dPercent); if (pNewPt == null) { MessageBox.Show("û�в������ٽ��ı�"); } else { pNetElements.QueryIDs(eid, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID); IMarkerSymbol pMarkerSym = new SimpleMarkerSymbolClass(); IRgbColor pRGBColor = new RgbColorClass(); pRGBColor.Red = 255; pRGBColor.Green = 0; pRGBColor.Blue = 0; pMarkerSym.Color = pRGBColor; pMarkerSym.Size = 20; //�����µ�Flag IEdgeFlagDisplay pEdgeFlagDisplay = new EdgeFlagDisplayClass(); IFlagDisplay pFlagDisplay = pEdgeFlagDisplay as IFlagDisplay; pFlagDisplay.Symbol = pMarkerSym as ISymbol; pFlagDisplay.Geometry = pNewPt; pFlagDisplay.FeatureClassID = iUserClassID; pFlagDisplay.FID = iUserID; pFlagDisplay.SubID = iUserSubID; //���Ƹõ� IScreenDisplay pScreenDisplay = axMapControl1.ActiveView.ScreenDisplay; pScreenDisplay.StartDrawing(pScreenDisplay.hDC, 0); pScreenDisplay.SetSymbol(pMarkerSym as ISymbol); pScreenDisplay.DrawPoint(pNewPt as IGeometry); pScreenDisplay.FinishDrawing(); BurstFindValves(pFlagDisplay); } } catch (Exception eX) { MessageBox.Show(eX.Message); } }
public override void OnMouseDown(int button, int Shift, int x, int y) { if (button != 1) { return; } this.SelectByClick(x, y); IMap map = _context.FocusMap; IEnumFeature enumFeature = (IEnumFeature)map.FeatureSelection; IFeature feature = enumFeature.Next(); if (feature == null) { if (Shift == 1) { this.m_SectionControl.RebuildSelection(); } else { this.m_SectionControl.LayerName = ""; this.m_SectionControl.Clear(); this._context.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _context.ActiveView.Extent); } } else { string aliasName = feature.Class.AliasName; int oID; if (feature.HasOID) { oID = feature.OID; } else { if (feature.FeatureType == esriFeatureType.esriFTSimpleEdge || feature.FeatureType == esriFeatureType.esriFTComplexEdge) { IPolyline egLine = feature.Shape as IPolyline; IPoint newCenter = new PointClass(); egLine.QueryPoint(esriSegmentExtension.esriNoExtension, 0.01, true, newCenter); IEdgeFeature pEgFeature = feature as IEdgeFeature; IFeatureClass pClass = feature.Class as IFeatureClass; INetworkClass pNetworkClass = pClass as INetworkClass; INetElements network = pNetworkClass.GeometricNetwork.Network as INetElements; IPointToEID pntEID = new PointToEIDClass(); pntEID.GeometricNetwork = pNetworkClass.GeometricNetwork; pntEID.SourceMap = _context.FocusMap; pntEID.SnapTolerance = CommonHelper.ConvertPixelsToMapUnits(_context.ActiveView, 5.0); double percent; int edgeID; IPoint location; pntEID.GetNearestEdge(newCenter, out edgeID, out location, out percent); if (percent == 0) { return; } int userClassID, userID, userSubID; network.QueryIDs(edgeID, esriElementType.esriETEdge, out userClassID, out userID, out userSubID); if (pClass.FeatureClassID == userClassID) { feature = pClass.GetFeature(userID); } else { IEnumDataset dses = pNetworkClass.FeatureDataset.Subsets; dses.Reset(); IDataset ds = dses.Next(); while (ds != null) { if (ds is IFeatureClass) { IFeatureClass pClass2 = ds as IFeatureClass; if (pClass2.FeatureClassID == userClassID) { feature = pClass2.GetFeature(userID); break; } } } } } oID = feature.OID; } if (Shift != 1) { this.m_SectionControl.Clear(); this.m_SectionControl.LayerName = aliasName; this.m_SectionControl.Add(oID); } else if (this.m_SectionControl.Count == 0) { this.m_SectionControl.LayerName = aliasName; this.m_SectionControl.Add(oID); } else if (this.m_SectionControl.IsInSameLayer(aliasName)) { this.m_SectionControl.LayerName = aliasName; this.m_SectionControl.Add(oID); } } }
public override void GetSelectedData() { this.method_3(); IMap map = this.m_context.FocusMap; ITopologicalOperator topologicalOperator = (ITopologicalOperator)this.m_pBaseLine; IGeometry geometry = topologicalOperator.Buffer(0.0); map.ClearSelection(); ISelectionEnvironment selectionEnvironment = new SelectionEnvironment(); map.SelectByShape(geometry, selectionEnvironment, false); IEnumFeature enumFeature = (IEnumFeature)map.FeatureSelection; IFeature feature = enumFeature.Next(); while (feature != null) { if (feature.FeatureType == esriFeatureType.esriFTSimpleEdge) { IPolyline egLine = feature.Shape as IPolyline; IPoint newCenter = new PointClass(); egLine.QueryPoint(esriSegmentExtension.esriNoExtension, 0.01, true, newCenter); IEdgeFeature pEgFeature = feature as IEdgeFeature; IFeatureClass pClass = feature.Class as IFeatureClass; INetworkClass pNetworkClass = pClass as INetworkClass; INetElements network = pNetworkClass.GeometricNetwork.Network as INetElements; IPointToEID pntEID = new PointToEIDClass(); pntEID.GeometricNetwork = pNetworkClass.GeometricNetwork; pntEID.SourceMap = m_context.FocusMap; pntEID.SnapTolerance = CommonHelper.ConvertPixelsToMapUnits(m_context.ActiveView, 5.0); double percent; int edgeID; IPoint location; pntEID.GetNearestEdge(newCenter, out edgeID, out location, out percent); if (percent == 0) { feature = enumFeature.Next(); continue; } int userClassID, userID, userSubID; network.QueryIDs(edgeID, esriElementType.esriETEdge, out userClassID, out userID, out userSubID); if (pClass.FeatureClassID == userClassID) { feature = pClass.GetFeature(userID); } else { IEnumDataset dses = pNetworkClass.FeatureDataset.Subsets; dses.Reset(); IDataset ds = dses.Next(); while (ds != null) { if (ds is IFeatureClass) { IFeatureClass pClass2 = ds as IFeatureClass; if (pClass2.FeatureClassID == userClassID) { feature = pClass2.GetFeature(userID); break; } } } } } string smpClassName = CommonUtils.GetSmpClassName(feature.Class.AliasName); IMAware mWAware = feature.Shape as IMAware; bool isMUsing = mWAware.MAware; IBasicLayerInfo lineConfig = PipeConfig.GetBasicLayerInfo(feature.Class.AliasName) as IBasicLayerInfo; if (lineConfig == null && !smpClassName.ToUpper().Contains("JT_JT_L") && !smpClassName.ToUpper().Contains("SY_ZX_L") && !smpClassName.ToUpper().Contains("ZB_LD_R")) { feature = enumFeature.Next(); } else { IGeometry shape = feature.Shape; if (shape.GeometryType != esriGeometryType.esriGeometryPolyline && shape.GeometryType != esriGeometryType.esriGeometryPolygon) { feature = enumFeature.Next(); } else { IPolyline polyline; if (shape.GeometryType == esriGeometryType.esriGeometryPolygon) { polyline = this.PolygonToPolyline((IPolygon)shape); } else { polyline = (IPolyline)shape; } GPoints gPoints = null; if (isMUsing) { gPoints = this.CalculateIntersections(this.m_pBaseLine, polyline); } else { gPoints = this.CalculateIntersections(this.m_pBaseLine, feature, lineConfig); } //string text = "管线性质"; string text = lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GDXZ); string bstrDatasetName = ""; int num = feature.Fields.FindField(text); if (num != -1) { object obj = feature.get_Value(num); if (obj == null || Convert.IsDBNull(obj)) { bstrDatasetName = ""; } else { bstrDatasetName = obj.ToString(); } } if (gPoints == null) { feature = enumFeature.Next(); } else { int num2 = gPoints.Size(); for (int i = 0; i < num2; i++) { GPoint gPoint = gPoints[i]; PipePoint pipePoint = new PipePoint(); if (smpClassName.ToUpper().Contains("JT_JT_L")) { pipePoint.PointType = PipePoint.SectionPointType.sptRoadBorder; } else if (smpClassName.ToUpper().Contains("SY_ZX_L")) { pipePoint.PointType = PipePoint.SectionPointType.sptMidRoadLine; } else if (smpClassName.ToUpper().Contains("ZB_LD_R")) { pipePoint.PointType = PipePoint.SectionPointType.sptMidGreen; } else { pipePoint.PointType = PipePoint.SectionPointType.sptPipe; } pipePoint.x = gPoint.X; pipePoint.y = gPoint.Y; pipePoint.z = gPoint.Z; pipePoint.m = gPoint.M; pipePoint.bstrDatasetName = bstrDatasetName; // int num3 = feature.Fields.FindField(base.PipeConfig.get_Material()); int num3 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GXCZ)); if (num3 == -1) { pipePoint.strMaterial = ""; } else { object obj2 = feature.get_Value(num3); if (obj2 != null) { pipePoint.strMaterial = feature.get_Value(num3).ToString(); } else { pipePoint.strMaterial = ""; } } // num3 = feature.Fields.FindField(base.PipeConfig.get_Diameter()); num3 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GJ)); string text2; if (num3 != -1 && feature.get_Value(num3) != null) { text2 = feature.get_Value(num3).ToString(); } else { text2 = ""; } num3 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.DMCC)); string text3; if (num3 != -1 && feature.get_Value(num3) != null) { text3 = feature.get_Value(num3).ToString(); } else { text3 = ""; } if (text2 != "") { pipePoint.strPipeWidthHeight = text2; } if (text3 != "") { pipePoint.strPipeWidthHeight = text3; } Color featureColor = CommonUtils.GetFeatureColor(map, feature.Class.AliasName, feature); pipePoint.Red = (int)featureColor.R; pipePoint.Green = (int)featureColor.G; pipePoint.Blue = (int)featureColor.B; this.m_arrPipePoints.Add(pipePoint); } feature = enumFeature.Next(); } } } } map.ClearSelection(); IPointCollection pointCollection = (IPointCollection)this.m_pBaseLine; int pointCount = pointCollection.PointCount; if (pointCount != 0) { for (int j = 0; j < pointCount; j++) { IPoint point = pointCollection.get_Point(j); double x = point.X; double y = point.Y; PipePoint pipePoint2 = new PipePoint(); pipePoint2.x = x; pipePoint2.y = y; pipePoint2.PointType = PipePoint.SectionPointType.sptDrawPoint; this.m_arrPipePoints.Add(pipePoint2); } this.fEswZsmwIx((PipePoint)this.m_arrPipePoints[this.m_arrPipePoints.Count - 2]); this.method_1(); if (this.method_2()) { this.method_5(this.m_arrPipePointsDraw, this.m_arrPipePoints); this.method_4(); this.method_7(this.m_arrPipePointsDraw); } } }
/// <summary> /// Adds edge flags for a feature layer /// </summary> /// <param name="layer">The feature layer</param> private void AddEdgeFlags(IFeatureLayer layer) { try { // QI all the network analysis interfaces INetworkAnalysisExt netAnalyst = (INetworkAnalysisExt)this.UtilityNetAnalysisExt; INetworkAnalysisExtFlags flags = (INetworkAnalysisExtFlags)this.UtilityNetAnalysisExt; INetworkAnalysisExtBarriers barriers = (INetworkAnalysisExtBarriers)this.UtilityNetAnalysisExt; IPointToEID point2EID = new PointToEIDClass(); point2EID.GeometricNetwork = this.NetworkAnalysisExt.CurrentNetwork; point2EID.SourceMap = ((IMxDocument)this.Application.Document).FocusMap; point2EID.SnapTolerance = this.SnapTolerance; INetElements networkElements = (INetElements)this.NetworkAnalysisExt.CurrentNetwork.Network; IFeatureSelection featureSelection = (IFeatureSelection)layer; ISelectionSet selectionSet = (ISelectionSet)featureSelection.SelectionSet; IEnumIDs ids = selectionSet.IDs; int i; while ((i = ids.Next()) > 0) { IFeature feature = layer.FeatureClass.GetFeature(i); IPoint locationPoint; int nearestEdgeID; double perCent; point2EID.GetNearestEdge((IPoint)feature.ShapeCopy, out nearestEdgeID, out locationPoint, out perCent); if (networkElements.IsValidElement(nearestEdgeID, esriElementType.esriETEdge)) { int userclassID; int userID; int usersubID; networkElements.QueryIDs(nearestEdgeID, esriElementType.esriETEdge, out userclassID, out userID, out usersubID); IFlagDisplay flagDisplay = new EdgeFlagDisplayClass(); flagDisplay.FeatureClassID = userclassID; flagDisplay.FID = userID; flagDisplay.SubID = usersubID; flagDisplay.Geometry = locationPoint; flagDisplay.Symbol = this.EdgeFlagSymbol; flags.AddEdgeFlag((IEdgeFlagDisplay)flagDisplay); this.AddFlagCount++; this.OnAddFlag(locationPoint); } else { this.OnAddFlagError(layer.Name, "No nearby edge feature.", feature.OID); } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.StackTrace); throw; } }
/// <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); } }