//返回路径的几何体 public IPolyline PathPolyLine() { IEIDInfo ipEIDInfo; IGeometry ipGeometry; if (m_ipPolyline != null) { return(m_ipPolyline); } m_ipPolyline = new PolylineClass(); IGeometryCollection ipNewGeometryColl = m_ipPolyline as IGeometryCollection;//引用传递 ISpatialReference ipSpatialReference = m_ipMap.SpatialReference; IEIDHelper ipEIDHelper = new EIDHelperClass(); ipEIDHelper.GeometricNetwork = m_ipGeometricNetwork; ipEIDHelper.OutputSpatialReference = ipSpatialReference; ipEIDHelper.ReturnGeometries = true; IEnumEIDInfo ipEnumEIDInfo = ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges); int count = ipEnumEIDInfo.Count; ipEnumEIDInfo.Reset(); for (int i = 0; i < count; i++) { ipEIDInfo = ipEnumEIDInfo.Next(); ipGeometry = ipEIDInfo.Geometry; ipNewGeometryColl.AddGeometryCollection(ipGeometry as IGeometryCollection); } return(m_ipPolyline); }
//返回路径 public bool PathPolyLine() { try { IEIDInfo ipEIDInfo; IGeometry ipGeometry; if (m_ipPolyline != null) return true; m_ipPolyline = new PolylineClass(); IGeometryCollection ipNewGeometryColl = m_ipPolyline as IGeometryCollection; ISpatialReference ipSpatialReference = m_ipMap.SpatialReference; IEIDHelper ipEIDHelper = new EIDHelperClass(); ipEIDHelper.GeometricNetwork = m_ipGeometricNetwork; ipEIDHelper.OutputSpatialReference = ipSpatialReference; ipEIDHelper.ReturnGeometries = true; IEnumEIDInfo ipEnumEIDInfo = ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges); int count = ipEnumEIDInfo.Count; ipEnumEIDInfo.Reset(); for (int i = 0; i < count; i++) { ipEIDInfo = ipEnumEIDInfo.Next(); ipGeometry = ipEIDInfo.Geometry; ipNewGeometryColl.AddGeometryCollection(ipGeometry as IGeometryCollection); } return true; } catch (Exception) { return false; } }
private void pathToPolyline() { try { IEIDHelper piEIDHelper = new EIDHelperClass(); piEIDHelper.GeometricNetwork = m_ipGeometricNetwork; piEIDHelper.OutputSpatialReference = m_HookHelper.ActiveView.FocusMap.SpatialReference; piEIDHelper.ReturnFeatures = true; IPolyline mPolyline = new PolylineClass(); mPolyline.SpatialReference = m_HookHelper.ActiveView.FocusMap.SpatialReference; IEIDInfo ipEIDInfo; IEnumEIDInfo piEnumEIDInfo; IGeometry ipGeometry = null; piEnumEIDInfo = piEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges); IGeometryCollection pGeoCollection = mPolyline as IGeometryCollection; piEnumEIDInfo.Reset(); object objMiss = Type.Missing; for (int ii = 0; ii < piEnumEIDInfo.Count; ii++) { ipEIDInfo = piEnumEIDInfo.Next(); ipGeometry = ipEIDInfo.Feature.Shape; if (ipGeometry != null) { Utility.drawPolyline(m_HookHelper.ActiveView, ipGeometry as IPolyline); } } //return ipGeometry as IPolyline; } catch (Exception e) { MessageBox.Show(e.Message); } finally{ mPointArray = null; m_ipEnumNetEID_Junctions = null; m_ipEnumNetEID_Edges = null; } }
/// <summary> /// 最短路径分析 /// </summary> /// <param name="pMap"></param> /// <param name="pGeometricNet"></param> /// <param name="pCollection"></param> /// <param name="weightName"></param> /// <param name="pDisc"></param> /// <returns></returns> public static IPolyline DistanceFun(IMap pMap, IGeometricNetwork pGeometricNet, IPointCollection pCollection, string weightName, double pDisc) { //几何网络分析接口 ITraceFlowSolverGEN pTraceFlowGen = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver pNetSolver = pTraceFlowGen as INetSolver; //获取网络 INetwork pNetwork = pGeometricNet.Network; //设置该网络为几何分析处理网络 pNetSolver.SourceNetwork = pNetwork; //网络元素 INetElements pNetElements = pNetwork as INetElements; //根据输入点建立旗帜数组 IJunctionFlag[] pJunctionFlags = GetJunctionFlags(pMap, pGeometricNet, pCollection, pDisc); //将旗帜数组添加到处理类中 pTraceFlowGen.PutJunctionOrigins(ref pJunctionFlags); //设置边线的权重 可以考虑使用点权重 SetWeight(weightName, pTraceFlowGen, pNetwork); //获取边线和交汇点的集合 IEnumNetEID junctionEIDs; IEnumNetEID netEIDS; object[] pRec = new object[pCollection.PointCount - 1]; pTraceFlowGen.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out junctionEIDs, out netEIDS, pCollection.PointCount - 1, ref pRec); //获取最短路径 IPolyline pPolyline = new PolylineClass(); IGeometryCollection pGeometryCollection = pPolyline as IGeometryCollection; ISpatialReference pSpatialReference = pMap.SpatialReference; IEIDHelper pEIDHelper = new EIDHelperClass(); pEIDHelper.GeometricNetwork = pGeometricNet; pEIDHelper.OutputSpatialReference = pSpatialReference; pEIDHelper.ReturnGeometries = true; IEnumEIDInfo pEnumEIDInfo = pEIDHelper.CreateEnumEIDInfo(netEIDS); int Count = pEnumEIDInfo.Count; pEnumEIDInfo.Reset(); for (int i = 0; i < Count; i++) { IEIDInfo pEIDInfo = pEnumEIDInfo.Next(); IGeometry pGeometry = pEIDInfo.Geometry; pGeometryCollection.AddGeometryCollection(pGeometry as IGeometryCollection); } return(pPolyline); }
/// <summary> /// Returns the <see cref="IEIDInfo" /> for the specified network element. /// </summary> /// <param name="source">The source.</param> /// <param name="eid">The element ID.</param> /// <param name="elementType">Type of the element.</param> /// <param name="returnFeatures">if set to <c>true</c> if the created IEIDInfo should contain features.</param> /// <param name="returnGeometries">if set to <c>true</c> if the created EIDInfo should contain geometries.</param> /// <returns> /// Returns the <see cref="IEIDInfo" /> interface for the network element. /// </returns> public static IEIDInfo GetEIDInfo(this IGeometricNetwork source, int eid, esriElementType elementType, bool returnFeatures, bool returnGeometries) { if (source == null) { return(null); } IEnumNetEID enumNetEID = source.CreateEnumNetEID(elementType, eid); IEIDHelper eidHelper = new EIDHelperClass(); eidHelper.GeometricNetwork = source; eidHelper.ReturnFeatures = returnFeatures; eidHelper.ReturnGeometries = returnGeometries; IEnumEIDInfo enumEIDInfo = eidHelper.CreateEnumEIDInfo(enumNetEID); IEIDInfo eidInfo = enumEIDInfo.Next(); return(eidInfo); }
public static void DrawPolyline(IScreenDisplay pDisplay) { if (m_ipPolyline == null) { if ((m_ipEnumNetEID_Junctions != null) && (m_ipEnumNetEID_Junctions.Count == 1)) { IEIDHelper helper = new EIDHelperClass { GeometricNetwork = m_pAnalystGN, ReturnGeometries = true }; IEnumEIDInfo info = helper.CreateEnumEIDInfo(m_ipEnumNetEID_Junctions); info.Reset(); IGeometry point = info.Next().Geometry; ISimpleMarkerSymbol symbol = new SimpleMarkerSymbolClass { Style = esriSimpleMarkerStyle.esriSMSCircle, Size = 2.0, Color = ColorManage.Red }; pDisplay.StartDrawing(0, -1); pDisplay.SetSymbol(symbol as ISymbol); pDisplay.DrawPoint(point); pDisplay.FinishDrawing(); } } else { ISimpleLineSymbol symbol2 = new SimpleLineSymbolClass { Style = esriSimpleLineStyle.esriSLSSolid, Width = 2.0, Color = ColorManage.Red }; pDisplay.StartDrawing(0, -1); pDisplay.SetSymbol(symbol2 as ISymbol); pDisplay.DrawPolyline(m_ipPolyline); pDisplay.FinishDrawing(); } }
private IPolyline PathToPolyLine() { IPolyline pPolyLine = new PolylineClass(); IGeometryCollection pNewGeometryCollection = pPolyLine as IGeometryCollection; if (mEnumNetEID_Edges == null) { return(null); } IEIDHelper pEIDHelper = new EIDHelperClass(); //获取几何网络 pEIDHelper.GeometricNetwork = mGeometricNetwork; //获取地图空间参考 ISpatialReference pSpatialReference = this.axMapControl1.Map.SpatialReference; pEIDHelper.OutputSpatialReference = pSpatialReference; pEIDHelper.ReturnGeometries = true; //根据边的ID获取边的信息 IEnumEIDInfo pEnumEIDInfo = pEIDHelper.CreateEnumEIDInfo(mEnumNetEID_Edges); int intCount = pEnumEIDInfo.Count; pEnumEIDInfo.Reset(); IEIDInfo pEIDInfo; IGeometry pGeometry; for (int i = 0; i < intCount; i++) { pEIDInfo = pEnumEIDInfo.Next(); //获取边的几何要素 pGeometry = pEIDInfo.Geometry; pNewGeometryCollection.AddGeometryCollection((IGeometryCollection)pGeometry); } return(pPolyLine); }
/// <summary> /// object polyline. Distance negative -> upstream /// </summary> /// <param name="geometricNetwork">object geometricNetwork</param> /// <param name="resultEdges">objects resultEdges</param> /// <param name="distance">value of distance</param> /// <param name="point">object point</param> /// <param name="offset">offset of polyline</param> /// <param name="messageInfo">info on result</param> /// <returns>object IGeometry (polyline or point)</returns> internal static IGeometry GetPolylinePosAlong(ESRI.ArcGIS.Geodatabase.IGeometricNetwork geometricNetwork, IEnumNetEID resultEdges, double distance, IPoint point, double?offset, ref string messageInfo) { IGeometry geometryBag = new GeometryBagClass(); geometryBag.SpatialReference = point.SpatialReference; IGeometryCollection geometryCollection = geometryBag as IGeometryCollection; IEIDHelper eidHelper = new EIDHelperClass(); eidHelper.GeometricNetwork = geometricNetwork; eidHelper.ReturnGeometries = true; eidHelper.ReturnFeatures = false; IEnumEIDInfo enumEIDinfo = eidHelper.CreateEnumEIDInfo(resultEdges); enumEIDinfo.Reset(); IEIDInfo eidInfo = enumEIDinfo.Next(); while (eidInfo != null) { IGeometry geometry = eidInfo.Geometry; geometryCollection.AddGeometry(geometry); eidInfo = enumEIDinfo.Next(); } ITopologicalOperator unionedPolyline = new PolylineClass(); unionedPolyline.ConstructUnion(geometryBag as IEnumGeometry); IPolyline pl = unionedPolyline as IPolyline; if (distance < 0) { pl.ReverseOrientation(); distance = Math.Abs(distance); } IMAware mAware = pl as IMAware; mAware.MAware = true; IMSegmentation3 mSegmentation = unionedPolyline as IMSegmentation3; mSegmentation.SetMsAsDistance(false); IPoint ptTmp = new PointClass(); double distanceAlong = 0; double distanceFromCurve = 0; bool rightSide = false; pl.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, ptTmp, ref distanceAlong, ref distanceFromCurve, ref rightSide); object mStartArray = mSegmentation.GetMsAtDistance(distanceAlong, false); double[] mStart = mStartArray as double[]; double distanceDownStream = distanceAlong + distance; IPolyline resultPolyline = mSegmentation.GetSubcurveBetweenMs(mStart[0], distanceDownStream) as IPolyline; if (resultPolyline.IsEmpty) { return(point); } if (mSegmentation.MMax < distanceDownStream) { messageInfo = "The set distance exceeds the length of network"; } return(Helper.ConstructOffset(resultPolyline, offset)); }
private static void ProfileGetRelatedElevData(IApplication app, List<ProfileGraphDetails> ProfileGraph, IGeometricNetwork pGeometricNet, IEnumNetEID pResultEdges, IEnumNetEID pResultJunctions, int CurrentDetail, ref IFeatureLayer pFLManhole, ref IFeatureLayer pFLMain, ref IFeatureLayer pFLTap) { List<mainDetails> SewerColMains = null; List<manholeDetails> SewerColManholes = null; List<tapDetails> SewerColTap = null; IEIDHelper pEIDHelperEdges = null; IEnumEIDInfo pEnumEIDInfoEdges = null; IEIDHelper pEIDHelperJunctions = null; IEnumEIDInfo pEnumEIDInfoJunctions = null; IPolyline pPolyline = null; IPointCollection pPtColl = null; IEIDInfo pEIDInfo = null; IPoint pNewPt = null; ISegmentCollection pSegColl = null; IMSegmentation pMSegmentation = null; IMAware pMAware = null; IPointCollection pPtCollection = null; IEnumVertex pEnumVertex; IHitTest pHtTest = null; IPoint pHitPntOne = null; IPoint pHitPntTwo = null; IFeature pFeature = null; Hashtable pFeatureAdded = null; mainDetails mainDet = null; IEdgeFeature pEdge = null; IPoint pGeoOne = null; IPoint pGeoTwo = null; IField pFld = null; IJunctionFeature pJunc = null; tapDetails tapDet = null; manholeDetails manDet = null; IFeatureLayer pFl = null; ISpatialFilter pSpatFilt = null; IFeatureCursor pFC = null; try { SewerColMains = new List<mainDetails>(); SewerColManholes = new List<manholeDetails>(); SewerColTap = new List<tapDetails>(); pEIDHelperEdges = new EIDHelper(); pEIDHelperEdges.GeometricNetwork = pGeometricNet; pEIDHelperEdges.ReturnFeatures = true; pEIDHelperEdges.ReturnGeometries = true; pEIDHelperEdges.PartialComplexEdgeGeometry = true; pEnumEIDInfoEdges = pEIDHelperEdges.CreateEnumEIDInfo(pResultEdges); pEnumEIDInfoEdges.Reset(); //edges pEIDHelperJunctions = new EIDHelperClass(); pEIDHelperJunctions.GeometricNetwork = pGeometricNet; pEIDHelperJunctions.ReturnFeatures = true; pEIDHelperJunctions.ReturnGeometries = true; pEIDHelperJunctions.PartialComplexEdgeGeometry = true; pEnumEIDInfoJunctions = pEIDHelperJunctions.CreateEnumEIDInfo(pResultJunctions); pEnumEIDInfoJunctions.Reset();// junctions pPolyline = new PolylineClass(); pPolyline.SpatialReference = (pFLMain as IGeoDataset).SpatialReference; pPtColl = (IPointCollection)pPolyline; //QI for (int i = 0; i < pEnumEIDInfoJunctions.Count; i++) { pEIDInfo = pEnumEIDInfoJunctions.Next(); pNewPt = (IPoint)pEIDInfo.Geometry; pPtColl.AddPoint(pNewPt); } pSegColl = (ISegmentCollection)pPolyline; pPolyline.Densify(50, 0.01); pMAware = (IMAware)pPolyline;//'QI pMAware.MAware = true; pMSegmentation = (IMSegmentation)pPolyline; // get the M values, put the distance in m, 0 to Length pMSegmentation.SetMsAsDistance(false); pPtCollection = (IPointCollection)pPolyline; pEnumVertex = pPtCollection.EnumVertices; pEnumVertex.Reset(); pHtTest = pPolyline as IHitTest; pHitPntOne = new PointClass(); pHitPntTwo = new PointClass(); double pHitDistOne = -1; double pHitDistTwo = -1; int pHitPrtOne = -1; int pHitPrtTwo = -1; int pHitSegOne = -1; int pHitSegTwo = -1; bool pHitSideOne = false; bool pHitSideTwo = false; pFeatureAdded = new Hashtable(); pEnumEIDInfoEdges.Reset(); //edges int intUpStreamFld = pFLMain.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Line_UpStreamElevationField); int intDownStreamFld = pFLMain.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Line_DownStreamElevationField); if (intDownStreamFld < 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19c") + ProfileGraph[CurrentDetail].Line_DownStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19b")); } if (intUpStreamFld < 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19d") + ProfileGraph[CurrentDetail].Line_UpStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19b")); } for (int i = 0; i < pResultEdges.Count; i++) { pEIDInfo = pEnumEIDInfoEdges.Next(); pFeature = pEIDInfo.Feature; if (((IDataset)pFeature.Class).Name != ((IDataset)pFLMain.FeatureClass).Name) continue; if (pFeatureAdded.ContainsValue(pFeature.OID)) continue; mainDet = new mainDetails(); pEdge = (IEdgeFeature)pFeature; pGeoOne = (IPoint)pEdge.FromJunctionFeature.get_OriginalGeometryForJunctionElement(0); pGeoTwo = (IPoint)pEdge.ToJunctionFeature.get_OriginalGeometryForJunctionElement(0); pFeature = ((IFeatureClass)pFeature.Class).GetFeature(pFeature.OID); bool bHitOne = pHtTest.HitTest(pGeoOne, .1, esriGeometryHitPartType.esriGeometryPartVertex, pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne); bool bHitTwo = pHtTest.HitTest(pGeoTwo, .1, esriGeometryHitPartType.esriGeometryPartVertex, pHitPntTwo, ref pHitDistTwo, ref pHitPrtTwo, ref pHitSegTwo, ref pHitSideTwo); if (bHitOne && bHitTwo) { if (pHitPntOne.M < pHitPntTwo.M) { mainDet.UpM = pHitPntOne.M; mainDet.DownM = pHitPntTwo.M; if (intUpStreamFld > 0) { if (pFeature.get_Value(intUpStreamFld).ToString() != "") { mainDet.UpElev = Convert.ToDouble(pFeature.get_Value(intUpStreamFld)); } else mainDet.UpElev = -9999; } else mainDet.UpElev = -9999; if (intDownStreamFld > 0) { if (pFeature.get_Value(intDownStreamFld).ToString() != "") { mainDet.DownElev = Convert.ToDouble(pFeature.get_Value(intDownStreamFld)); } else mainDet.DownElev = -9999; } else mainDet.DownElev = -9999; } else { mainDet.DownM = pHitPntOne.M; mainDet.UpM = pHitPntTwo.M; if (intUpStreamFld > 0) { if (pFeature.get_Value(intUpStreamFld) != null && pFeature.get_Value(intUpStreamFld).ToString() != "") { mainDet.DownElev = Convert.ToDouble(pFeature.get_Value(intUpStreamFld)); } else mainDet.DownElev = -9999; } else mainDet.DownElev = -9999; if (intDownStreamFld > 0) { if (pFeature.get_Value(intDownStreamFld) != null && pFeature.get_Value(intDownStreamFld).ToString() != "") { mainDet.UpElev = Convert.ToDouble(pFeature.get_Value(intDownStreamFld)); } else mainDet.UpElev = -9999; } else mainDet.UpElev = -9999; } string label = ""; for (int l = 0; l < ProfileGraph[CurrentDetail].Line_Labels.Length; l++) { if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_Labels[l]) > 0) { int fldIdx = pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_Labels[l]); pFld = pFeature.Fields.get_Field(fldIdx); if (pFeature.get_Value(fldIdx) != null) { if (label == "") { label = Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld); } else { label = label + "\r\n" + Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld); } } } } mainDet.Label = label; } if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField)).ToString() != "") { mainDet.MainID = Convert.ToString(pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField))); } else mainDet.MainID = "Unk"; } else mainDet.MainID = "Unk"; pFeatureAdded.Add(pFeature.OID, pFeature.OID); SewerColMains.Add(mainDet); } pFeatureAdded = new Hashtable(); pEnumEIDInfoJunctions.Reset(); for (int i = 0; i < pEnumEIDInfoJunctions.Count; i++) { pEIDInfo = pEnumEIDInfoJunctions.Next(); pFeature = pEIDInfo.Feature; if (pFLTap != null) { if (((IDataset)pFeature.Class).Name == ((IDataset)pFLTap.FeatureClass).Name) { pJunc = (IJunctionFeature)pFeature; pFeature = ((IFeatureClass)pFeature.Class).GetFeature(pFeature.OID); pHitPntOne = new PointClass(); bool bHit = pHtTest.HitTest(pFeature.Shape as IPoint, .1, esriGeometryHitPartType.esriGeometryPartVertex, pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne); if (bHit) { tapDet = new tapDetails(); tapDet.M = pHitPntOne.M; if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField)).ToString() != "") { tapDet.tapID = pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField)).ToString(); } else tapDet.tapID = "Unk"; } else tapDet.tapID = "Unk"; string label = ""; for (int l = 0; l < ProfileGraph[CurrentDetail].PointAlong_Labels.Length; l++) { if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_Labels[l]) > 0) { int fldIdx = pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_Labels[l]); pFld = pFeature.Fields.get_Field(fldIdx); if (pFeature.get_Value(fldIdx) != null) { if (label == "") { label = Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld); } else { label = label + "\r\n" + Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld); } } } } tapDet.tapLabel = label; SewerColTap.Add(tapDet); } } } if (((IDataset)pFeature.Class).Name == ((IDataset)pFLManhole.FeatureClass).Name) { if (pFeatureAdded.ContainsValue(pFeature.OID)) continue; pJunc = (IJunctionFeature)pFeature; pFeature = ((IFeatureClass)pFeature.Class).GetFeature(pFeature.OID); pHitPntOne = new PointClass(); bool bHit = pHtTest.HitTest(pFeature.Shape as IPoint, .1, esriGeometryHitPartType.esriGeometryPartVertex, pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne); if (bHit) { manDet = new manholeDetails(); manDet.M = pHitPntOne.M; if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField)).ToString() != "") { manDet.Top = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField)); } else manDet.Top = -9999; } else manDet.Top = -9999; if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField)).ToString() != "") { manDet.Bottom = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField)); if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField)).ToString() != "") { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField)).ToString().ToUpper() == "INVERT") manDet.Bottom = manDet.Top - (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField)); } } } else manDet.Bottom = -9999; } else manDet.Bottom = -9999; //if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField) > 0) //{ // if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField)).ToString() != "") // { // manDet.InvertElev = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField)); // } // else // manDet.InvertElev = -9999; //} //else // manDet.InvertElev = -9999; //if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField) > 0) //{ // if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField)).ToString() != "") // { // manDet.Invert = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField)); // } // else // manDet.Invert = -9999; //} //else // manDet.Invert = -9999; //if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField) > 0) //{ // if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField)).ToString() != "") // { // manDet.Rim = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField)); // } // else // manDet.Rim = -9999; //} //else // manDet.Rim = -9999; if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField)).ToString() != "") { manDet.ManholeID = pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField)).ToString(); } else manDet.ManholeID = "UNK"; } else manDet.ManholeID = "UNK"; pFeatureAdded.Add(pFeature.OID, pFeature.OID); SewerColManholes.Add(manDet); } } } if (ProfileGraph[CurrentDetail].Lines_Along != null) { if (ProfileGraph[CurrentDetail].Lines_Along.Length > 0) { pSpatFilt = new SpatialFilterClass(); pSpatFilt.Geometry = pPolyline; pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; for (int i = 0; i < ProfileGraph[CurrentDetail].Lines_Along.Length; i++) { bool FCorLayerTemp = true; pFl = (IFeatureLayer)Globals.FindLayer(app, ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name, ref FCorLayerTemp); if (pFl != null) { intUpStreamFld = pFl.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Lines_Along[i].Line_UpStreamElevationField); intDownStreamFld = pFl.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Lines_Along[i].Line_DownStreamElevationField); int intIdFld = pFl.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Lines_Along[i].Line_IDField); if (intIdFld < 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19f") + ProfileGraph[CurrentDetail].Lines_Along[i].Line_IDField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19e") + ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name); } if (intDownStreamFld < 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19c") + ProfileGraph[CurrentDetail].Lines_Along[i].Line_DownStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19e") + ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name); } if (intUpStreamFld < 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19d") + ProfileGraph[CurrentDetail].Lines_Along[i].Line_UpStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19e") + ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name); } pSpatFilt.GeometryField = pFl.FeatureClass.ShapeFieldName; pFC = pFl.Search(pSpatFilt, true); } } } } ProfileCreateGraph(app, ProfileGraph, pPolyline, SewerColMains, SewerColManholes, SewerColTap, CurrentDetail); } catch (Exception Ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + "ProfileGetRelatedSewerElevData " + Ex.Message); } finally { SewerColMains = null; SewerColManholes = null; SewerColTap = null; pEIDHelperEdges = null; pEnumEIDInfoEdges = null; pEIDHelperJunctions = null; if (pEnumEIDInfoJunctions != null) Marshal.ReleaseComObject(pEnumEIDInfoJunctions); pEnumEIDInfoJunctions = null; pPolyline = null; pPtColl = null; pEIDInfo = null; pNewPt = null; pSegColl = null; pMSegmentation = null; pMAware = null; pPtCollection = null; pEnumVertex = null; pHtTest = null; pHitPntOne = null; pHitPntTwo = null; pFeature = null; pFeatureAdded = null; mainDet = null; pEdge = null; pGeoOne = null; pGeoTwo = null; pFld = null; pJunc = null; tapDet = null; manDet = null; pFl = null; pSpatFilt = null; if (pFC != null) Marshal.ReleaseComObject(pFC); pFC = null; } }
public static string TraceIsolation(double[] x, double[] y, IApplication app, string sourceFLName, string valveFLName, string operableFieldNameValves, string operableFieldNameSources, double snapTol, bool processEvent, string[] opValues, string addSQL, bool traceIndeterminate, bool ZeroSourceCont, bool selectEdges, string MeterName, string MeterCritField, string MeterCritVal) { IMap map = null; List<int> valveFCClassIDs = new List<int>(); IProgressDialogFactory pProDFact = null; IStepProgressor pStepPro = null; IProgressDialog2 pProDlg = null; ITrackCancel pTrkCan = null; int pointAlong = 0; List<IGeometricNetwork> gnList = null; int gnIdx; IGeometricNetwork gn = null; IPoint snappedPoint = null; int EID = -1; double distanceAlong; List<INetFlag> startNetFlag = null; List<IFlagDisplay> pFlagsDisplay = null; //Find feature classes string[] sourceFLs; IFeatureClass[] sourceFC = null; IFeatureLayer[] sourceFL = null; List<int> sourceFCClassIDs = new List<int>(); string[] strValveFLs; IFeatureLayer pTempLay = null; List<IFeatureLayer> valveFLs = null; List<IFeatureClass> valveFCs = null; //IFeatureLayer meterFL = null; // string meterDSName; IJunctionFlag[] junctionFlag = null; IEdgeFlag[] edgeFlag = null; ITraceFlowSolverGEN traceFlowSolver = null; INetSolver netSolver = null; INetElementBarriersGEN netElementBarriers = null; INetElementBarriers nb = null; IEnumNetEID juncEIDs = null; IEnumNetEID edgeEIDs = null; IEIDInfo eidInfo = null; IEIDInfo valveEIDInfo = null; IEIDInfo sourceEIDInfo = null; IEIDInfo vEIDInfo = null; List<int[]> userIds = null; IEIDHelper eidHelper = null; List<Hashtable> valveEIDInfoHT = null; Hashtable sourceEIDInfoHT = null; System.Object[] segCosts = null; ISelectionSetBarriers netElementBarrier = null; List<IEdgeFlag> pEdgeFlags = null; List<IJunctionFlag> pJunctionFlags = null; //List<IEdgeFlag> pEdgeFlagsBar = null; //List<IJunctionFlag> pJunctionFlagsBar = null; INetElementBarriers pEdgeElementBarriers = null; INetElementBarriers pJunctionElementBarriers = null; ISelectionSetBarriers pSelectionSetBarriers = null; List<INetFlag> pNetFlags; //ITraceResult traceRes = null; IFlagDisplay pFlagDisplay = null; INetworkAnalysisExt pNetAnalysisExt = null; UID pID = null; IJunctionFlag[] junctionFlags = null; IEdgeFlag[] edgeFlags = null; Hashtable noSourceValveHT = null; Hashtable hasSourceValveHT = null; List<BarClassIDS> barrierIds = null; Hashtable sourceDirectEIDInfoHT = null; INetFlag netFlag1 = null; INetFlag netFlag2 = null; try { map = ((app.Document as IMxDocument).FocusMap); bool boolCont = true; if (processEvent) { // Create a CancelTracker pTrkCan = new CancelTrackerClass(); // Create the ProgressDialog. This automatically displays the dialog pProDFact = new ProgressDialogFactoryClass(); pProDlg = (IProgressDialog2)pProDFact.Create(pTrkCan, 0); // Set the properties of the ProgressDialog pProDlg.CancelEnabled = true; pProDlg.Description = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDesc_16a"); pProDlg.Title = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsTitle_16a"); pProDlg.Animation = esriProgressAnimationTypes.esriProgressGlobe; // Set the properties of the Step Progressor pStepPro = (IStepProgressor)pProDlg; pStepPro.MinRange = 0; pStepPro.MaxRange = 18; pStepPro.StepValue = 1; pStepPro.Position = 0; pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_4"); pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_14a"); pStepPro.Step(); boolCont = pTrkCan.Continue(); if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } } if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_4"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } pointAlong++; gnList = Globals.GetGeometricNetworksCurrentlyVisible(ref map); gnIdx = -1; if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_14a"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } pointAlong++; // Create junction or edge flag at start of trace - also returns geometric network, snapped point, and EID of junction if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15a"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } startNetFlag = new List<INetFlag>();// null;// Globals.GetJunctionFlag(x, y, map, ref gnList, snapTol, ref gnIdx, out snappedPoint, out EID) as INetFlag; //if (startNetFlag == null) pFlagsDisplay = new List<IFlagDisplay>(); if (x != null) { for (int l = 0; l < x.Length; l++) { startNetFlag.Add(Globals.GetEdgeFlag(x[l], y[l], ref map, ref gnList, snapTol, ref gnIdx, out snappedPoint, out EID, out distanceAlong, out pFlagDisplay, true) as INetFlag); pFlagsDisplay.Add(pFlagDisplay); } } pointAlong++; //Set network to trace if (gnIdx > -1) gn = gnList[gnIdx] as IGeometricNetwork; if (app != null) { pID = new UID(); pID.Value = "esriEditorExt.UtilityNetworkAnalysisExt"; pNetAnalysisExt = (INetworkAnalysisExt)app.FindExtensionByCLSID(pID); if (gn != null) { Globals.SetCurrentNetwork(ref pNetAnalysisExt, ref gn); } traceFlowSolver = Globals.CreateTraceFlowSolverFromToolbar(ref pNetAnalysisExt, out pEdgeFlags, out pJunctionFlags, out pEdgeElementBarriers, out pJunctionElementBarriers, out pSelectionSetBarriers) as ITraceFlowSolverGEN; gn = pNetAnalysisExt.CurrentNetwork; netSolver = traceFlowSolver as INetSolver; } else { if (gn == null || startNetFlag.Count == 0) { return A4LGSharedFunctions.Localizer.GetString("NoFlagReturnStatement"); } traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = gn.Network; } traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate; pNetFlags = new List<INetFlag>(); if (pEdgeFlags != null) { foreach (IEdgeFlag pEdFl in pEdgeFlags) { pNetFlags.Add((INetFlag)pEdFl); } } if (pJunctionFlags != null) { foreach (IJunctionFlag pJcFl in pJunctionFlags) { pNetFlags.Add((INetFlag)pJcFl); } } if (startNetFlag != null) { if (startNetFlag.Count > 0) { foreach (INetFlag pNF in startNetFlag) { if (pNF != null) { pNetFlags.Add((INetFlag)pNF); } } } // pNetFlags.Add((INetFlag)startNetFlag); } if (pNetFlags.Count == 0) { return A4LGSharedFunctions.Localizer.GetString("AddFlagOrClickReturnStatement"); } // Stop if user point was not on a visible network feature, old trace results and selection are cleared if (gn == null || pNetFlags.Count == 0) { return A4LGSharedFunctions.Localizer.GetString("NotIntersectReturnStatement"); } pointAlong++; if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16a"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } //Find feature classes sourceFLs = sourceFLName.Split('|'); sourceFC = new IFeatureClass[sourceFLs.Length]; sourceFL = new IFeatureLayer[sourceFLs.Length]; for (int i = 0; i < sourceFLs.Length; i++) { bool FCorLayerTemp = true; sourceFL[i] = (IFeatureLayer)Globals.FindLayer(map, sourceFLs[i], ref FCorLayerTemp); if (sourceFL[i] != null) { sourceFC[i] = sourceFL[i].FeatureClass; sourceFCClassIDs.Add(sourceFL[i].FeatureClass.FeatureClassID); } } pointAlong++; // IFeatureClass sourceFC = (IFeatureClass)Globals.GetFeatureClassFromGeometricNetwork(sourceFCName, gn, esriFeatureType.esriFTSimpleJunction); // IFeatureClass valveFC = (IFeatureClass)Globals.GetFeatureClassFromGeometricNetwork(valveFCName, gn, esriFeatureType.esriFTSimpleJunction); strValveFLs = valveFLName.Split('|'); valveFLs = new List<IFeatureLayer>();//(IFeatureLayer)Globals.FindLayer(map, valveFLName); valveFCs = new List<IFeatureClass>();//[strValveFLs.Length]; for (int i = 0; i < strValveFLs.Length; i++) { bool FCorLayerTemp = true; pTempLay = (IFeatureLayer)Globals.FindLayer(map, strValveFLs[i], ref FCorLayerTemp); if (pTempLay != null) { if (pTempLay.FeatureClass != null) { valveFLs.Add(pTempLay); valveFCs.Add(pTempLay.FeatureClass); valveFCClassIDs.Add(pTempLay.FeatureClass.FeatureClassID); } } } // string strMeterFL = meterFLName; //meterFL = (IFeatureLayer)Globals.FindLayer(map, meterFLName); //meterDSName = ""; //if (meterFL != null) //{ // if (meterFL is IDataset) // { // IDataset pTempDataset = (IDataset)meterFL; // meterDSName = pTempDataset.BrowseName; // if (meterDSName.Contains(".")) // { // meterDSName = meterDSName.Substring(meterDSName.LastIndexOf(".") + 1); // } // Marshal.ReleaseComObject(pTempDataset); // pTempDataset = null; // } //} //meterFL = null; if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16a"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } pointAlong++; if (valveFCs == null) { if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15d") + valveFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15e") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15f"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); ; } return A4LGSharedFunctions.Localizer.GetString("LambdaReturnStatement") + valveFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15e") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15f"); } pointAlong++; if (valveFCs.Count == 0) { if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15d") + valveFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15e") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15f"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } return A4LGSharedFunctions.Localizer.GetString("LambdaReturnStatement") + valveFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15e") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15f"); } if (sourceFC == null) { if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15d") + sourceFLs + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15e") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15f"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } return A4LGSharedFunctions.Localizer.GetString("LambdaReturnStatement") + sourceFLs + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15e") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15f"); } pointAlong++; if (sourceFC.Length == 0) { if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15d") + sourceFLs + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15e") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15f"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } return A4LGSharedFunctions.Localizer.GetString("LambdaReturnStatement") + sourceFLs + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15e") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15f"); } pointAlong++; if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16b"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } Globals.AddFlagsToTraceSolver(pNetFlags.ToArray(), ref traceFlowSolver, out junctionFlags, out edgeFlags); if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16c"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } //Create barriers based on all operable valves pointAlong++; netElementBarriers = new NetElementBarriersClass() as INetElementBarriersGEN; netElementBarriers.ElementType = esriElementType.esriETJunction; netElementBarriers.Network = gn.Network; userIds = Globals.GetOperableValveOIDs(valveFCs.ToArray(), operableFieldNameValves, opValues, addSQL); if (userIds == null) { if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16d"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } } else { if (userIds.Count == 0) { if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16d"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } } else { try { int idxUser = 0; if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16e"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } foreach (IFeatureClass valveFC in valveFCs) { int[] usrid = userIds[idxUser]; if (usrid.Length > 0) { netElementBarriers.SetBarriers(valveFC.FeatureClassID, ref usrid); //error here after sum nb = netElementBarriers as INetElementBarriers; netSolver.set_ElementBarriers(esriElementType.esriETJunction, nb); } idxUser++; } } catch (Exception Ex) { if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_16a") + Ex.Message; pStepPro.Step(); boolCont = pTrkCan.Continue(); return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } } } } pointAlong++; if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16f"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } try { traceFlowSolver.FindFlowEndElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctionsAndEdges, out juncEIDs, out edgeEIDs); } catch { juncEIDs = null; edgeEIDs = null; if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + "FindFlowEndElements"; pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } return A4LGSharedFunctions.Localizer.GetString("DontFindFlowEltReturnStatement"); //MessageBox.Show("Error in the FindFlowEndElements"); } pointAlong++; eidHelper = new EIDHelperClass(); eidHelper.GeometricNetwork = gn; eidHelper.ReturnFeatures = true; //Save valves which stopped the trace if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16g"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } pointAlong++; valveEIDInfoHT = new List<Hashtable>(); int totalreachcount = 0; foreach (IFeatureClass valveFC in valveFCs) { if (valveFC != null) { Hashtable valveEIDInfoHTtemp = Globals.GetEIDInfoListByFC(valveFC.FeatureClassID, juncEIDs, eidHelper); totalreachcount = totalreachcount + valveEIDInfoHTtemp.Count; valveEIDInfoHT.Add(valveEIDInfoHTtemp); } } if (totalreachcount == 0) { if (processEvent) { pStepPro.Message = (A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16a") + valveFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15c") + Environment.NewLine + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16b") + valveFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16c") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16d") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16e")); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } return A4LGSharedFunctions.Localizer.GetString("Error") + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16a") + valveFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15c") + Environment.NewLine + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16b") + valveFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16c") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16d") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16e"); } pointAlong++; if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16h"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate; netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = gn.Network; //Globals.AddFlagsToTraceSolver(startNetFlag.ToArray(), ref traceFlowSolver, out junctionFlag, out edgeFlag); Globals.AddFlagsToTraceSolver(pNetFlags.ToArray(), ref traceFlowSolver, out junctionFlag, out edgeFlag); Globals.AddBarriersToSolver(ref traceFlowSolver, ref pEdgeElementBarriers, ref pJunctionElementBarriers, ref pSelectionSetBarriers); pointAlong++; foreach (int sFC in sourceFCClassIDs) { netSolver.DisableElementClass(sFC); } traceFlowSolver.FindFlowEndElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctions, out juncEIDs, out edgeEIDs); pointAlong++; //Save sources which are reachable if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16i"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } sourceEIDInfoHT = new Hashtable(); //foreach (IFeatureClass sFC in sourceFC) //{ Globals.GetEIDInfoListByFCWithHT(ref sourceEIDInfoHT, sourceFCClassIDs, operableFieldNameSources, opValues, juncEIDs, eidHelper); //} pointAlong++; if (sourceEIDInfoHT.Count == 0) { if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("No") + sourceFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15c") + Environment.NewLine + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16b") + sourceFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16c") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16j"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return null; } return A4LGSharedFunctions.Localizer.GetString("Error") + A4LGSharedFunctions.Localizer.GetString("No") + sourceFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15c") + Environment.NewLine + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16b") + sourceFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16c") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16j"); } if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16k"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return null; } traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate; netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = gn.Network; //Globals.AddFlagsToTraceSolver(startNetFlag.ToArray(), ref traceFlowSolver, out junctionFlag, out edgeFlag); Globals.AddFlagsToTraceSolver(pNetFlags.ToArray(), ref traceFlowSolver, out junctionFlag, out edgeFlag); Globals.AddBarriersToSolver(ref traceFlowSolver, ref pEdgeElementBarriers, ref pJunctionElementBarriers, ref pSelectionSetBarriers); pointAlong++; //Set the barriers in the network based on the saved valves if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16l"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } //Run the trace to find directly reachable sources (without passing valve) if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16m"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } netElementBarrier = new SelectionSetBarriersClass(); totalreachcount = 0; foreach (Hashtable HTentry in valveEIDInfoHT) { foreach (DictionaryEntry entry in HTentry) { eidInfo = entry.Value as IEIDInfo; netElementBarrier.Add(eidInfo.Feature.Class.ObjectClassID, eidInfo.Feature.OID); } totalreachcount++; } pointAlong++; netSolver.SelectionSetBarriers = netElementBarrier; pointAlong++; Globals.AddBarriersToSolver(ref traceFlowSolver, ref pEdgeElementBarriers, ref pJunctionElementBarriers, ref pSelectionSetBarriers); traceFlowSolver.FindFlowElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctionsAndEdges, out juncEIDs, out edgeEIDs); // Hashtable sourceDirectEIDInfoHT = Globals.GetEIDInfoListByFC(sourceFC.FeatureClassID, juncEIDs, eidHelper); sourceDirectEIDInfoHT = new Hashtable(); Globals.GetEIDInfoListByFCWithHT(ref sourceDirectEIDInfoHT, sourceFCClassIDs, operableFieldNameSources, opValues, juncEIDs, eidHelper); //Remove directly reachable sources from source array if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16n"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } pointAlong++; foreach (DictionaryEntry entry in sourceDirectEIDInfoHT) { eidInfo = entry.Value as IEIDInfo; sourceEIDInfoHT.Remove(eidInfo.Feature.OID); } pointAlong++;//21 if (sourceEIDInfoHT.Count == 0) { if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("No") + sourceFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16o") + Environment.NewLine + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16b") + sourceFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16c") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16j"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } return A4LGSharedFunctions.Localizer.GetString("Error") + A4LGSharedFunctions.Localizer.GetString("No") + sourceFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16o") + Environment.NewLine + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16b") + sourceFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_16c") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16j"); } pointAlong++;//22 if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16p"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } noSourceValveHT = new Hashtable(); hasSourceValveHT = new Hashtable(); // IEIDInfo vEIDInfo; barrierIds = null; bool foundSource; // ArrayList barrierArrayList; pointAlong++; totalreachcount = 0; foreach (Hashtable valveHT in valveEIDInfoHT) { foreach (DictionaryEntry valveEntry in valveHT) { foundSource = false; valveEIDInfo = valveEntry.Value as IEIDInfo; //Create array of all isolation valves excluding the current one // barrierArrayList = new ArrayList(); barrierIds = new List<BarClassIDS>(); foreach (Hashtable valveHTBar in valveEIDInfoHT) { BarClassIDS barClID = new BarClassIDS(); List<int> tempIntArr = new List<int>(); foreach (DictionaryEntry valveEntryBar in valveHTBar) { vEIDInfo = valveEntryBar.Value as IEIDInfo; barClID.ClassID = vEIDInfo.Feature.Class.ObjectClassID; vEIDInfo = valveEntryBar.Value as IEIDInfo; if (vEIDInfo.Feature.OID == valveEIDInfo.Feature.OID && vEIDInfo.Feature.Class.ObjectClassID == valveEIDInfo.Feature.Class.ObjectClassID) { } else { // barrierArrayList.Add(vEIDInfo.Feature.OID); tempIntArr.Add(vEIDInfo.Feature.OID); //barrierIds.Add(vEIDInfo.Feature.OID); } } barClID.IDs = tempIntArr.ToArray(); barrierIds.Add(barClID); } //if (valveHT.Count > 1) //{ // barrierArrayList = new ArrayList(); // barrierIds = new int[valveHT.Count - 1]; // foreach (DictionaryEntry v in valveHT) // { // vEIDInfo = v.Value as IEIDInfo; // if (vEIDInfo.Feature.OID != valveEIDInfo.Feature.OID) // { // barrierArrayList.Add(vEIDInfo.Feature.OID); // } // } // barrierArrayList.CopyTo(barrierIds); //} //else // barrierArrayList = null; pointAlong++; //For each source, attempt to trace foreach (DictionaryEntry sourceEntry in sourceEIDInfoHT) { sourceEIDInfo = sourceEntry.Value as IEIDInfo; //Setup trace to test each valve traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate; netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = gn.Network; Globals.AddBarriersToSolver(ref traceFlowSolver, ref pEdgeElementBarriers, ref pJunctionElementBarriers, ref pSelectionSetBarriers); //Set the first junction flag for path finding based this current valve netFlag1 = new JunctionFlagClass(); netFlag1.UserClassID = valveEIDInfo.Feature.Class.ObjectClassID; netFlag1.UserID = valveEIDInfo.Feature.OID; netFlag1.UserSubID = 0; netFlag1.Label = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_16a"); //AddFlagToTraceSolver(netFlag1, ref traceFlowSolver, out junctionFlag, out edgeFlag); //Set the second (and last) trace flag at this source netFlag2 = new JunctionFlagClass(); netFlag2.UserClassID = sourceEIDInfo.Feature.Class.ObjectClassID; netFlag2.UserID = sourceEIDInfo.Feature.OID; netFlag2.UserSubID = 0; netFlag2.Label = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_16b"); Globals.AddTwoJunctionFlagsToTraceSolver(ref traceFlowSolver, netFlag1, netFlag2); //Set as isolation valves (except the current one) as barriers if (barrierIds != null && barrierIds.Count > 0) { netElementBarriers = new NetElementBarriersClass() as INetElementBarriersGEN; netElementBarriers.ElementType = esriElementType.esriETJunction; netElementBarriers.Network = gn.Network; bool setBar = false; foreach (BarClassIDS tempBarIDS in barrierIds) { if (tempBarIDS.IDs.Length > 0) { int[] barIDs = tempBarIDS.IDs; netElementBarriers.SetBarriers(tempBarIDS.ClassID, ref barIDs); setBar = true; } } if (setBar)//required, it would produce an error if there where no other barriers { nb = netElementBarriers as INetElementBarriers; netSolver.set_ElementBarriers(esriElementType.esriETJunction, nb); } } //Run trace segCosts = new System.Object[1]; segCosts[0] = new System.Object(); edgeEIDs = null; traceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out juncEIDs, out edgeEIDs, 1, ref segCosts); if (edgeEIDs != null && edgeEIDs.Count > 0) { foundSource = true; break; } } // End of source loop pointAlong++;//25 -30ish if (foundSource) { hasSourceValveHT.Add(valveEIDInfo.Feature.OID, valveEIDInfo);//valveEIDInfo.Feature.Class.ObjectClassID +":" + } else { noSourceValveHT.Add(valveEIDInfo.Feature.OID, valveEIDInfo); } } // End of valve loop totalreachcount++; } //Setup last trace with correct valve barriers if (hasSourceValveHT.Count == 0) { if (ZeroSourceCont) hasSourceValveHT = noSourceValveHT; else return A4LGSharedFunctions.Localizer.GetString("NoWaterSourceIdentifiedReturnStatement"); } if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_16q"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } pointAlong++; traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate; netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = gn.Network; //Globals.AddFlagsToTraceSolver(startNetFlag.ToArray(), ref traceFlowSolver, out junctionFlag, out edgeFlag); Globals.AddFlagsToTraceSolver(pNetFlags.ToArray(), ref traceFlowSolver, out junctionFlag, out edgeFlag); Globals.AddBarriersToSolver(ref traceFlowSolver, ref pEdgeElementBarriers, ref pJunctionElementBarriers, ref pSelectionSetBarriers); //Set the barriers in the network based on the saved valves netElementBarrier = new SelectionSetBarriersClass(); foreach (DictionaryEntry entry in hasSourceValveHT) { eidInfo = entry.Value as IEIDInfo; //netElementBarrier.Add(valveFC.FeatureClassID, eidInfo.Feature.OID); netElementBarrier.Add(((IFeatureClass)eidInfo.Feature.Class).FeatureClassID, eidInfo.Feature.OID); } netSolver.SelectionSetBarriers = netElementBarrier; pointAlong++; //Run last trace traceFlowSolver.FindFlowElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctionsAndEdges, out juncEIDs, out edgeEIDs); //skipped valves => //Hashtable skippedValvesEIDInfoHT = GetEIDInfoListByFC(valveFC.FeatureClassID, juncEIDs, eidHelper); //Select junction features pointAlong++; //51,44 //Open identify dialog with selected features //IdentifySelected(map); if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("Complete"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } if (snappedPoint != null) { snappedPoint.Project(map.SpatialReference); // traceRes.TracePoint = snappedPoint; } // return "Post1"; //Globals.LoadJunctions(ref traceRes, ref gn, ref map, ref juncEIDs, ref meterDSName); // Globals.LoadValves(ref traceRes, ref gn, ref map, ref hasSourceValveHT); //Globals.LoadEdges(ref traceRes, ref gn, ref map, ref edgeEIDs); //((IMxDocument)app.Document).FocusMap.ClearSelection(); //Globals.RemoveGraphics(((IMxDocument)app.Document).FocusMap, false); string returnVal = ""; returnVal = Globals.SelectJunctions(ref map, ref gn, ref juncEIDs, ref junctionFlag, MeterName, MeterCritField, MeterCritVal, processEvent); if (processEvent) { if (selectEdges) Globals.SelectEdges(ref map, ref gn, ref edgeEIDs); else Globals.DrawEdges(ref map, ref gn, ref edgeEIDs); } returnVal = Globals.SelectValveJunctions(ref map, ref hasSourceValveHT, ref valveFLs, processEvent) + "_" + returnVal; if (processEvent) { if (pNetAnalysisExt != null) { foreach (IFlagDisplay pFgDi in pFlagsDisplay) { Globals.AddFlagToGN(ref pNetAnalysisExt, ref gn, pFgDi); // Globals.AddPointGraphic(map, pFgDi.Geometry as IPoint, false); } } else { foreach (IFlagDisplay pFgDi in pFlagsDisplay) { // Globals.AddFlagToGN(ref pNetAnalysisExt, ref gn, pFgDi); Globals.AddPointGraphic(map, pFgDi.Geometry as IPoint, false); } } Globals.GetCommand("esriArcMapUI.ZoomToSelectedCommand", app).Execute(); } return returnVal; } catch (Exception ex) { // MessageBox.Show(ex.ToString()); return ex.Message.ToString() + "\n" + pointAlong; } finally { barrierIds = null; sourceDirectEIDInfoHT = null; netFlag1 = null; netFlag2 = null; junctionFlags = null; edgeFlags = null; pID = null; noSourceValveHT = null; hasSourceValveHT = null; if (pProDlg != null) { pProDlg.HideDialog(); } pStepPro = null; pProDlg = null; pProDFact = null; if (gnList != null) { // Marshal.ReleaseComObject(gnList); } if (gn != null) { Marshal.ReleaseComObject(gn); } if (snappedPoint != null) { Marshal.ReleaseComObject(snappedPoint); } if (startNetFlag != null) { // Marshal.ReleaseComObject(startNetFlag); } if (sourceFC != null) { // Marshal.ReleaseComObject(sourceFC); } if (sourceFL != null) { // Marshal.ReleaseComObject(sourceFL); } if (pTempLay != null) { Marshal.ReleaseComObject(pTempLay); } if (valveFLs != null) { // Marshal.ReleaseComObject(valveFLs); } if (valveFCs != null) { // Marshal.ReleaseComObject(valveFCs); } //if (meterFL != null) //{ // Marshal.ReleaseComObject(meterFL); //} if (junctionFlag != null) { // Marshal.ReleaseComObject(junctionFlag); } if (edgeFlag != null) { // Marshal.ReleaseComObject(edgeFlag); } if (traceFlowSolver != null) { Marshal.ReleaseComObject(traceFlowSolver); } if (netSolver != null) { Marshal.ReleaseComObject(netSolver); } if (netElementBarriers != null) { Marshal.ReleaseComObject(netElementBarriers); } if (nb != null) { Marshal.ReleaseComObject(nb); } if (juncEIDs != null) { Marshal.ReleaseComObject(juncEIDs); } if (edgeEIDs != null) { Marshal.ReleaseComObject(edgeEIDs); } if (eidInfo != null) { Marshal.ReleaseComObject(eidInfo); } if (valveEIDInfo != null) { Marshal.ReleaseComObject(valveEIDInfo); } if (sourceEIDInfo != null) { Marshal.ReleaseComObject(sourceEIDInfo); } if (vEIDInfo != null) { Marshal.ReleaseComObject(vEIDInfo); } if (userIds != null) { // Marshal.ReleaseComObject(userIds); } if (eidHelper != null) { Marshal.ReleaseComObject(eidHelper); } if (valveEIDInfoHT != null) { // Marshal.ReleaseComObject(valveEIDInfoHT); } if (sourceEIDInfoHT != null) { // Marshal.ReleaseComObject(sourceEIDInfoHT); } if (segCosts != null) { // Marshal.ReleaseComObject(segCosts); } if (netElementBarrier != null) { Marshal.ReleaseComObject(netElementBarrier); } //if (traceRes != null) //{ // traceRes.Dispose(); // // Marshal.ReleaseComObject(traceRes); //} pNetAnalysisExt = null; pFlagsDisplay = null; pEdgeFlags = null; pJunctionFlags = null; pNetFlags = null; pFlagDisplay = null; //pEdgeFlagsBar = null; //pJunctionFlagsBar = null; gnList = null; gn = null; snappedPoint = null; startNetFlag = null; sourceFC = null; sourceFL = null; pTempLay = null; valveFLs = null; valveFCs = null; //meterFL = null; junctionFlag = null; edgeFlag = null; traceFlowSolver = null; netSolver = null; netElementBarriers = null; nb = null; juncEIDs = null; edgeEIDs = null; eidInfo = null; valveEIDInfo = null; sourceEIDInfo = null; vEIDInfo = null; userIds = null; eidHelper = null; valveEIDInfoHT = null; sourceEIDInfoHT = null; segCosts = null; netElementBarrier = null; //traceRes = null; } GC.Collect(); GC.WaitForFullGCComplete(300); }
public static string TraceFindClosest(double[] x, double[] y, IApplication app, string targetFLName, string sWeightName, double snapTol, bool processEvent, bool traceIndeterminate) { IMap map = null; IProgressDialogFactory pProDFact = null; IStepProgressor pStepPro = null; IProgressDialog2 pProDlg = null; ITrackCancel pTrkCan = null; List<IGeometricNetwork> gnList = null; int gnIdx; IGeometricNetwork gn = null; IPoint snappedPoint = null; int EID = -1; double distanceAlong; List<INetFlag> startNetFlag = null; List<IFlagDisplay> pFlagsDisplay = null; //Find feature classes IJunctionFlag[] junctionFlag = null; IEdgeFlag[] edgeFlag = null; ITraceFlowSolverGEN traceFlowSolver = null; INetSolver netSolver = null; INetElementBarriersGEN netElementBarriers = null; INetElementBarriers nb = null; IEnumNetEID juncEIDs = null; IEnumNetEID edgeEIDs = null; IEIDInfo eidInfo = null; IEIDInfo valveEIDInfo = null; IEIDInfo sourceEIDInfo = null; IEIDInfo vEIDInfo = null; List<int[]> userIds = null; IEIDHelper eidHelper = null; List<Hashtable> valveEIDInfoHT = null; Hashtable sourceEIDInfoHT = null; System.Object[] segCosts = null; ISelectionSetBarriers netElementBarrier = null; List<IEdgeFlag> pEdgeFlags = null; List<IJunctionFlag> pJunctionFlags = null; //List<IEdgeFlag> pEdgeFlagsBar = null; //List<IJunctionFlag> pJunctionFlagsBar = null; INetElementBarriers pEdgeElementBarriers = null; INetElementBarriers pJunctionElementBarriers = null; ISelectionSetBarriers pSelectionSetBarriers = null; List<INetFlag> pNetFlags; //ITraceResult traceRes = null; IFlagDisplay pFlagDisplay = null; INetworkAnalysisExt pNetAnalysisExt = null; UID pID = null; IJunctionFlag[] junctionFlags = null; IEdgeFlag[] edgeFlags = null; List<BarClassIDS> barrierIds = null; Hashtable sourceDirectEIDInfoHT = null; INetFlag netFlag1 = null; INetFlag netFlag2 = null; Hashtable htClosestAsset = null; IFeatureLayer pClosestLayer = null; INetwork pNetwork = null; INetSchema pNetSchema = null; INetWeight pNetWeight = null; INetSolverWeights pNetSolverW = null; try { map = ((app.Document as IMxDocument).FocusMap); bool boolCont = true; if (processEvent) { // Create a CancelTracker pTrkCan = new CancelTrackerClass(); // Create the ProgressDialog. This automatically displays the dialog pProDFact = new ProgressDialogFactoryClass(); pProDlg = (IProgressDialog2)pProDFact.Create(pTrkCan, 0); // Set the properties of the ProgressDialog pProDlg.CancelEnabled = true; pProDlg.Description = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDesc_15a"); pProDlg.Title = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsTitle_15a"); pProDlg.Animation = esriProgressAnimationTypes.esriProgressGlobe; // Set the properties of the Step Progressor pStepPro = (IStepProgressor)pProDlg; pStepPro.MinRange = 0; pStepPro.MaxRange = 18; pStepPro.StepValue = 1; pStepPro.Position = 0; pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_4"); pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_14a"); pStepPro.Step(); boolCont = pTrkCan.Continue(); if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } } if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_4"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } gnList = Globals.GetGeometricNetworksCurrentlyVisible(ref map); gnIdx = -1; if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_14a"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } // Create junction or edge flag at start of trace - also returns geometric network, snapped point, and EID of junction if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15a"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } startNetFlag = new List<INetFlag>();// null;// Globals.GetJunctionFlag(x, y, map, ref gnList, snapTol, ref gnIdx, out snappedPoint, out EID) as INetFlag; //if (startNetFlag == null) pFlagsDisplay = new List<IFlagDisplay>(); if (x != null) { for (int l = 0; l < x.Length; l++) { startNetFlag.Add(Globals.GetEdgeFlag(x[l], y[l], ref map, ref gnList, snapTol, ref gnIdx, out snappedPoint, out EID, out distanceAlong, out pFlagDisplay, true) as INetFlag); pFlagsDisplay.Add(pFlagDisplay); } } //Set network to trace if (gnIdx > -1) gn = gnList[gnIdx] as IGeometricNetwork; if (app != null) { pID = new UID(); pID.Value = "esriEditorExt.UtilityNetworkAnalysisExt"; pNetAnalysisExt = (INetworkAnalysisExt)app.FindExtensionByCLSID(pID); if (gn != null) { Globals.SetCurrentNetwork(ref pNetAnalysisExt, ref gn); } traceFlowSolver = Globals.CreateTraceFlowSolverFromToolbar(ref pNetAnalysisExt, out pEdgeFlags, out pJunctionFlags, out pEdgeElementBarriers, out pJunctionElementBarriers, out pSelectionSetBarriers) as ITraceFlowSolverGEN; gn = pNetAnalysisExt.CurrentNetwork; netSolver = traceFlowSolver as INetSolver; } else { if (gn == null || startNetFlag.Count == 0) { return A4LGSharedFunctions.Localizer.GetString("NoFlagReturnStatement"); } traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = gn.Network; } traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate; pNetFlags = new List<INetFlag>(); if (pEdgeFlags != null) { foreach (IEdgeFlag pEdFl in pEdgeFlags) { pNetFlags.Add((INetFlag)pEdFl); } } if (pJunctionFlags != null) { foreach (IJunctionFlag pJcFl in pJunctionFlags) { pNetFlags.Add((INetFlag)pJcFl); } } if (startNetFlag != null) { if (startNetFlag.Count > 0) { foreach (INetFlag pNF in startNetFlag) { if (pNF != null) { pNetFlags.Add((INetFlag)pNF); } } } // pNetFlags.Add((INetFlag)startNetFlag); } if (pNetFlags.Count == 0) { return A4LGSharedFunctions.Localizer.GetString("AddFlagOrClickReturnStatement"); } // Stop if user point was not on a visible network feature, old trace results and selection are cleared if (gn == null || pNetFlags.Count == 0) { return A4LGSharedFunctions.Localizer.GetString("NotIntersectReturnStatement"); } bool fndAsLayer = false; pClosestLayer = Globals.FindLayer(app, targetFLName, ref fndAsLayer) as IFeatureLayer; if (pClosestLayer == null) { return A4LGSharedFunctions.Localizer.GetString("LayerNotFoundReturnStatement"); } if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_15a"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } try { Globals.AddFlagsToTraceSolver(pNetFlags.ToArray(), ref traceFlowSolver, out junctionFlag, out edgeFlag); traceFlowSolver.FindFlowElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctions, out juncEIDs, out edgeEIDs); } catch { juncEIDs = null; edgeEIDs = null; if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + "FindFlowEndElements"; pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } return A4LGSharedFunctions.Localizer.GetString("DontFindFlowEltReturnStatement"); //MessageBox.Show("Error in the FindFlowEndElements"); } eidHelper = new EIDHelperClass(); eidHelper.GeometricNetwork = gn; eidHelper.ReturnFeatures = true; //Save valves which stopped the trace if (processEvent) { pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_15b"); pStepPro.Step(); boolCont = pTrkCan.Continue(); } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } if (pClosestLayer.FeatureClass != null) { htClosestAsset = Globals.GetEIDInfoListByFC(pClosestLayer.FeatureClass.FeatureClassID, juncEIDs, eidHelper); } if (htClosestAsset.Count == 0) { if (processEvent) { pStepPro.Message = (A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15b") + targetFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15c")); pStepPro.Step(); boolCont = pTrkCan.Continue(); return A4LGSharedFunctions.Localizer.GetString("NoFeaturesReturnStatement"); } } if (!boolCont) { pStepPro.Hide(); pProDlg.HideDialog(); pStepPro = null; pProDlg = null; pProDFact = null; return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); } traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate; netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = gn.Network; ////Globals.AddFlagsToTraceSolver(startNetFlag.ToArray(), ref traceFlowSolver, out junctionFlag, out edgeFlag); //Globals.AddFlagsToTraceSolver(pNetFlags.ToArray(), ref traceFlowSolver, out junctionFlag, out edgeFlag); Globals.AddBarriersToSolver(ref traceFlowSolver, ref pEdgeElementBarriers, ref pJunctionElementBarriers, ref pSelectionSetBarriers); pNetwork = gn.Network; pNetSchema = pNetwork as INetSchema; for (int i = 0; i < pNetSchema.WeightCount; i++) { pNetWeight = pNetSchema.get_Weight(i); if (pNetWeight.WeightName == sWeightName) break; } if (pNetWeight != null) { if (pNetWeight.WeightType == esriWeightType.esriWTBitGate || pNetWeight.WeightType == esriWeightType.esriWTNull) { pNetWeight = null; } } //Get trace weights if (pNetWeight != null) { pNetSolverW = traceFlowSolver as INetSolverWeights; pNetSolverW.JunctionWeight = pNetWeight; pNetSolverW.FromToEdgeWeight = pNetWeight; pNetSolverW.ToFromEdgeWeight = pNetWeight; } double shortest = 9999999.9; int pntAlong = 0; foreach (DictionaryEntry entry in htClosestAsset) { pntAlong++; ////Set the first junction flag for path finding based this current valve //netFlag1 = new JunctionFlagClass(); //netFlag1.UserClassID = valveEIDInfo.Feature.Class.ObjectClassID; //netFlag1.UserID = valveEIDInfo.Feature.OID; //netFlag1.UserSubID = 0; //netFlag1.Label = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_16a"); //AddFlagToTraceSolver(netFlag1, ref traceFlowSolver, out junctionFlag, out edgeFlag); // startNetFlag[0].Label = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_16a"); // startNetFlag[0].UserSubID = 0; //Set the second (and last) trace flag at this source //netFlag2 = new JunctionFlagClass(); //eidInfo = entry.Value as IEIDInfo; //netFlag2.UserClassID = eidInfo.Feature.Class.ObjectClassID; //netFlag2.UserID = eidInfo.Feature.OID; //netFlag2.UserSubID = 0; //netFlag2.Label = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_16b"); eidInfo = entry.Value as IEIDInfo; IPoint pTmpPnt = eidInfo.Feature.Shape as IPoint; //ref point, ref map, ref gn, snapTol, out snappedPoint, // out EID, out distanceAlong, out pFlagDisplay, Flag); bool Flag = true; netFlag2 = Globals.GetEdgeFlagWithGN(ref pTmpPnt, ref map, ref gn, snapTol, out snappedPoint, out EID, out distanceAlong, out pFlagDisplay, Flag) as INetFlag; // Globals.AddTwoJunctionFlagsToTraceSolver(ref traceFlowSolver, netFlag1, netFlag2); Globals.AddTwoJunctionFlagsToTraceSolver(ref traceFlowSolver, startNetFlag[0], netFlag2); //Run trace segCosts = new System.Object[1]; segCosts[0] = new System.Object(); edgeEIDs = null; object pTotalCost = null; IEnumNetEID pJuncSel = null; IEnumNetEID pEdgeSel = null; //traceFlowSolver.FindAccumulation(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctionsAndEdges, out pJuncSel, out pEdgeSel,out pTotalCost); traceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out juncEIDs, out edgeEIDs, 1, ref segCosts); if (Convert.ToDouble(segCosts[0]) < shortest) { shortest = Convert.ToDouble(segCosts[0]); } string test = ""; // if (edgeEIDs != null && edgeEIDs.Count > 0) // { // // foundSource = true; // // break; // } } MessageBox.Show(shortest.ToString()); //if (!boolCont) //{ // pStepPro.Hide(); // pProDlg.HideDialog(); // pStepPro = null; // pProDlg = null; // pProDFact = null; // return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); //} //pointAlong++; //traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; //traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate; //netSolver = traceFlowSolver as INetSolver; //netSolver.SourceNetwork = gn.Network; ////Globals.AddFlagsToTraceSolver(startNetFlag.ToArray(), ref traceFlowSolver, out junctionFlag, out edgeFlag); //Globals.AddFlagsToTraceSolver(pNetFlags.ToArray(), ref traceFlowSolver, out junctionFlag, out edgeFlag); //Globals.AddBarriersToSolver(ref traceFlowSolver, ref pEdgeElementBarriers, ref pJunctionElementBarriers, ref pSelectionSetBarriers); ////Set the barriers in the network based on the saved valves //netElementBarrier = new SelectionSetBarriersClass(); //foreach (DictionaryEntry entry in hasSourceValveHT) //{ // eidInfo = entry.Value as IEIDInfo; // //netElementBarrier.Add(valveFC.FeatureClassID, eidInfo.Feature.OID); // netElementBarrier.Add(((IFeatureClass)eidInfo.Feature.Class).FeatureClassID, eidInfo.Feature.OID); //} //netSolver.SelectionSetBarriers = netElementBarrier; //pointAlong++; ////Run last trace //traceFlowSolver.FindFlowElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctionsAndEdges, out juncEIDs, out edgeEIDs); ////skipped valves => //Hashtable skippedValvesEIDInfoHT = GetEIDInfoListByFC(valveFC.FeatureClassID, juncEIDs, eidHelper); ////Select junction features //pointAlong++; //51,44 ////Open identify dialog with selected features ////IdentifySelected(map); //if (processEvent) //{ // pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("Complete"); // pStepPro.Step(); // boolCont = pTrkCan.Continue(); //} //if (!boolCont) //{ // pStepPro.Hide(); // pProDlg.HideDialog(); // pStepPro = null; // pProDlg = null; // pProDFact = null; // return A4LGSharedFunctions.Localizer.GetString("CanceledReturnStatement"); //} //if (snappedPoint != null) //{ // snappedPoint.Project(map.SpatialReference); // // traceRes.TracePoint = snappedPoint; //} //// return "Post1"; ////Globals.LoadJunctions(ref traceRes, ref gn, ref map, ref juncEIDs, ref meterDSName); //// Globals.LoadValves(ref traceRes, ref gn, ref map, ref hasSourceValveHT); ////Globals.LoadEdges(ref traceRes, ref gn, ref map, ref edgeEIDs); ////((IMxDocument)app.Document).FocusMap.ClearSelection(); ////Globals.RemoveGraphics(((IMxDocument)app.Document).FocusMap, false); //string returnVal = ""; //returnVal = Globals.SelectJunctions(ref map, ref gn, ref juncEIDs, ref junctionFlag, MeterName, MeterCritField, MeterCritVal, processEvent); //if (processEvent) //{ // if (selectEdges) // Globals.SelectEdges(ref map, ref gn, ref edgeEIDs); // else // Globals.DrawEdges(ref map, ref gn, ref edgeEIDs); //} //returnVal = Globals.SelectValveJunctions(ref map, ref hasSourceValveHT, ref valveFLs, processEvent) + "_" + returnVal; //if (processEvent) //{ // if (pNetAnalysisExt != null) // { // foreach (IFlagDisplay pFgDi in pFlagsDisplay) // { // Globals.AddFlagToGN(ref pNetAnalysisExt, ref gn, pFgDi); // // Globals.AddPointGraphic(map, pFgDi.Geometry as IPoint, false); // } // } // else // { // foreach (IFlagDisplay pFgDi in pFlagsDisplay) // { // // Globals.AddFlagToGN(ref pNetAnalysisExt, ref gn, pFgDi); // Globals.AddPointGraphic(map, pFgDi.Geometry as IPoint, false); // } // } // Globals.GetCommand("esriArcMapUI.ZoomToSelectedCommand", app).Execute(); //} string returnVal = ""; return returnVal; } catch (Exception ex) { // MessageBox.Show(ex.ToString()); return ex.Message.ToString(); } finally { barrierIds = null; sourceDirectEIDInfoHT = null; netFlag1 = null; netFlag2 = null; junctionFlags = null; edgeFlags = null; pID = null; if (pProDlg != null) { pProDlg.HideDialog(); } pStepPro = null; pProDlg = null; pProDFact = null; if (gnList != null) { // Marshal.ReleaseComObject(gnList); } if (gn != null) { Marshal.ReleaseComObject(gn); } if (snappedPoint != null) { Marshal.ReleaseComObject(snappedPoint); } if (startNetFlag != null) { // Marshal.ReleaseComObject(startNetFlag); } if (junctionFlag != null) { Marshal.ReleaseComObject(junctionFlag); } if (edgeFlag != null) { // Marshal.ReleaseComObject(edgeFlag); } if (traceFlowSolver != null) { Marshal.ReleaseComObject(traceFlowSolver); } if (netSolver != null) { Marshal.ReleaseComObject(netSolver); } if (netElementBarriers != null) { Marshal.ReleaseComObject(netElementBarriers); } if (nb != null) { Marshal.ReleaseComObject(nb); } if (juncEIDs != null) { Marshal.ReleaseComObject(juncEIDs); } if (edgeEIDs != null) { Marshal.ReleaseComObject(edgeEIDs); } if (eidInfo != null) { Marshal.ReleaseComObject(eidInfo); } if (valveEIDInfo != null) { Marshal.ReleaseComObject(valveEIDInfo); } if (sourceEIDInfo != null) { Marshal.ReleaseComObject(sourceEIDInfo); } if (vEIDInfo != null) { Marshal.ReleaseComObject(vEIDInfo); } if (userIds != null) { // Marshal.ReleaseComObject(userIds); } if (eidHelper != null) { Marshal.ReleaseComObject(eidHelper); } if (valveEIDInfoHT != null) { // Marshal.ReleaseComObject(valveEIDInfoHT); } if (sourceEIDInfoHT != null) { // Marshal.ReleaseComObject(sourceEIDInfoHT); } if (segCosts != null) { // Marshal.ReleaseComObject(segCosts); } if (netElementBarrier != null) { Marshal.ReleaseComObject(netElementBarrier); } //if (traceRes != null) //{ // traceRes.Dispose(); // // Marshal.ReleaseComObject(traceRes); //} pNetAnalysisExt = null; pFlagsDisplay = null; pEdgeFlags = null; pJunctionFlags = null; pNetFlags = null; pFlagDisplay = null; //pEdgeFlagsBar = null; //pJunctionFlagsBar = null; gnList = null; gn = null; snappedPoint = null; startNetFlag = null; junctionFlag = null; edgeFlag = null; traceFlowSolver = null; netSolver = null; netElementBarriers = null; nb = null; juncEIDs = null; edgeEIDs = null; eidInfo = null; valveEIDInfo = null; sourceEIDInfo = null; vEIDInfo = null; userIds = null; eidHelper = null; valveEIDInfoHT = null; sourceEIDInfoHT = null; segCosts = null; netElementBarrier = null; //traceRes = null; } GC.Collect(); GC.WaitForFullGCComplete(300); }
/// <summary> /// return a featureSet from EIDs /// </summary> /// <param name="eids">object EIDs</param> /// <param name="featureSets">array JsonObject featureSet</param> protected void GetTrace(IEnumNetEID eids, out JsonObject[] featureSets) { IEIDHelper eidHelper = new EIDHelperClass(); eidHelper.GeometricNetwork = this.geometricNetwork; eidHelper.ReturnGeometries = true; eidHelper.ReturnFeatures = true; Dictionary <int, IPair <List <int>, IFeatureClass> > dictionary = new Dictionary <int, IPair <List <int>, IFeatureClass> >(); IEnumEIDInfo enumEIDinfo = eidHelper.CreateEnumEIDInfo(eids); enumEIDinfo.Reset(); IEIDInfo eidInfo = enumEIDinfo.Next(); while (eidInfo != null) { IFeatureClass featureClass = eidInfo.Feature.Class as IFeatureClass; IFeature feature = eidInfo.Feature; int featureClassID = featureClass.FeatureClassID; if (!dictionary.ContainsKey(featureClassID)) { IPair <List <int>, IFeatureClass> pair = new Pair <List <int>, IFeatureClass>(new List <int>(), featureClass); dictionary.Add(featureClassID, pair); } dictionary[featureClassID].First.Add(feature.OID); eidInfo = enumEIDinfo.Next(); } List <JsonObject> jsonObjects = new List <JsonObject>(); foreach (int i in dictionary.Keys) { IPair <List <int>, IFeatureClass> pair = dictionary[i]; List <int> listOIDs = pair.First; IFeatureClass featureClass = pair.Second; IQueryFilter2 queryFilter = new QueryFilterClass(); if (this.OutFields[0] != "*") { List <string> listFields = new List <string>(); Array.ForEach( this.OutFields, s => { if (featureClass.Fields.FindField(s) != -1) { listFields.Add(s); } }); if (listFields.Count == 0) { queryFilter.SubFields = featureClass.OIDFieldName; } else { listFields.Each((s, index) => { if (index == 0) { queryFilter.SubFields = s; } else { queryFilter.AddField(s); } }); if (!Array.Exists(this.OutFields, s => s == featureClass.OIDFieldName)) { queryFilter.AddField(featureClass.OIDFieldName); } if (!Array.Exists(this.OutFields, s => s == featureClass.ShapeFieldName)) { queryFilter.AddField(featureClass.ShapeFieldName); } } } queryFilter.WhereClause = featureClass.OIDFieldName + " IN (" + string.Join(",", Array.ConvertAll <int, string>(listOIDs.ToArray(), s => s.ToString(CultureInfo.InvariantCulture))) + ")"; IRecordSet recordset = Helper.ConvertToRecordset(featureClass, queryFilter); jsonObjects.Add(new JsonObject(Encoding.UTF8.GetString(Conversion.ToJson(recordset)))); } featureSets = jsonObjects.ToArray(); }
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); }
/// <summary> /// solve isolation /// </summary> /// <returns>object JsonObject</returns> public override JsonObject Solve() { try { if ((this.edgeFlags.Length == 0) && (this.junctionFlags.Length == 0)) { string message = "No input valid flags found"; if (this.flagNotFound.Count == 0) { throw new GeometricNetworkException(message); } else { JsonObject error = (new ObjectError(message)).ToJsonObject(); error.AddArray("flagsNotFound", Helper.GetListJsonObjects(this.flagNotFound)); return(error); } } INetwork network = this.geometricNetwork.Network; ITraceFlowSolverGEN traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = network; this.SetFlagsOrigin(ref traceFlowSolver); ////now create barries based on valves INetElementBarriersGEN netElementBarriersGEN = new NetElementBarriersClass() as INetElementBarriersGEN; netElementBarriersGEN.ElementType = esriElementType.esriETJunction; netElementBarriersGEN.Network = network; int[] userIds = Helper.GetOIDs(this.Valve); netElementBarriersGEN.SetBarriers(this.Valve.FeatureClassID, ref userIds); INetElementBarriers netElementBarriers = netElementBarriersGEN as INetElementBarriers; netSolver.set_ElementBarriers(esriElementType.esriETJunction, netElementBarriers); IEnumNetEID junctionEIDs; IEnumNetEID edgeEIDs; traceFlowSolver.FindFlowEndElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs); IEIDHelper eidHelper = new EIDHelperClass(); eidHelper.GeometricNetwork = this.geometricNetwork; eidHelper.ReturnFeatures = true; List <IEIDInfo> valveEIDInfoHT = Helper.GetEIDInfoListByFeatureClass(this.Valve.FeatureClassID, junctionEIDs, eidHelper); traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = network; this.SetFlagsOrigin(ref traceFlowSolver); netSolver.DisableElementClass(this.Station.FeatureClassID); traceFlowSolver.FindFlowEndElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctions, out junctionEIDs, out edgeEIDs); List <IEIDInfo> sourceEIDInfoHT = Helper.GetEIDInfoListByFeatureClass(this.Station.FeatureClassID, junctionEIDs, eidHelper); ////set up trace to find directly reachable sources traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = network; this.SetFlagsOrigin(ref traceFlowSolver); ////set barriers in the network based on the saved valves ISelectionSetBarriers netElementBarrier = new SelectionSetBarriersClass(); foreach (IEIDInfo eidInfo in valveEIDInfoHT) { netElementBarrier.Add(this.Valve.FeatureClassID, eidInfo.Feature.OID); } netSolver.SelectionSetBarriers = netElementBarrier; ////run trace to find directly reachable sources(without passing valve) traceFlowSolver.FindFlowElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs); List <IEIDInfo> sourceDirectEIDInfoHT = Helper.GetEIDInfoListByFeatureClass(this.Station.FeatureClassID, junctionEIDs, eidHelper); ////remove directly reachable sources from source array foreach (IEIDInfo eidInfo in sourceDirectEIDInfoHT) { sourceEIDInfoHT.RemoveAll(x => x.Feature.OID == eidInfo.Feature.OID); } List <IEIDInfo> noSourceValveHT = new List <IEIDInfo>(); List <IEIDInfo> hasSourceValveHT = new List <IEIDInfo>(); List <int> listBarrierIds; bool foundSource; foreach (IEIDInfo valve in valveEIDInfoHT) { foundSource = false; ////create array of all isolation valve excluding the current one listBarrierIds = new List <int>(); if (valveEIDInfoHT.Count > 1) { listBarrierIds.AddRange(valveEIDInfoHT.ConvertAll <int>(i => i.Feature.OID)); if (listBarrierIds.Contains(valve.Feature.OID)) { listBarrierIds.Remove(valve.Feature.OID); } } ////for each source attempt to trace INetFlag netFlag1; INetFlag netFlag2; foreach (IEIDInfo source in sourceEIDInfoHT) { ////setup trace to test each valve traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = network; ////set the first junction flag for path finding based this current valve netFlag1 = new JunctionFlagClass(); netFlag1.UserClassID = valve.Feature.Class.ObjectClassID; netFlag1.UserID = valve.Feature.OID; netFlag1.UserSubID = 0; netFlag1.Label = "Origin"; ////set the second and last trace flag at this source netFlag2 = new JunctionFlagClass(); netFlag2.UserClassID = source.Feature.Class.ObjectClassID; netFlag2.UserID = source.Feature.OID; netFlag2.UserSubID = 0; netFlag2.Label = "Destination"; Helper.AddTwoJunctionFlagsToTraceSolver(ref traceFlowSolver, netFlag1, netFlag2); if (listBarrierIds.Count > 0) { netElementBarriersGEN = new NetElementBarriersClass() as INetElementBarriersGEN; netElementBarriersGEN.ElementType = esriElementType.esriETJunction; netElementBarriersGEN.Network = network; int[] barrierIds = listBarrierIds.ToArray(); netElementBarriersGEN.SetBarriers(this.Valve.FeatureClassID, ref barrierIds); netElementBarriers = netElementBarriersGEN as INetElementBarriers; netSolver.set_ElementBarriers(esriElementType.esriETJunction, netElementBarriers); } ////run trace object[] segCosts = new object[1]; segCosts[0] = new object(); edgeEIDs = null; traceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out junctionEIDs, out edgeEIDs, 1, ref segCosts); if (edgeEIDs != null && edgeEIDs.Count > 0) { foundSource = true; break; } } if (foundSource) { hasSourceValveHT.Add(valve); } else { noSourceValveHT.Add(valve); } } traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = network; this.SetFlagsOrigin(ref traceFlowSolver); ////set the barrier in the network based on the saved valves netElementBarrier = new SelectionSetBarriersClass(); foreach (IEIDInfo eidInfo in hasSourceValveHT) { netElementBarrier.Add(this.Valve.FeatureClassID, eidInfo.Feature.OID); } netSolver.SelectionSetBarriers = netElementBarrier; ////run last trace traceFlowSolver.FindFlowElements(esriFlowMethod.esriFMConnected, this.FlowElements, out junctionEIDs, out edgeEIDs); ////deal with out put juncEIDs and edgeEIDs JsonObject objectJson = new JsonObject(); this.SetResults(ref objectJson, edgeEIDs, junctionEIDs); objectJson.AddArray("flagsNotFound", Helper.GetListJsonObjects(this.flagNotFound)); ////valves if (hasSourceValveHT.Count > 0) { JsonObject[] featureSetValves; this.GetTrace(Helper.GetEnumNetEID(hasSourceValveHT, esriElementType.esriETJunction), out featureSetValves); objectJson.AddJsonObject("valves", featureSetValves[0]); } return(objectJson); } catch (Exception e) { return((new ObjectError(e.Message)).ToJsonObject()); } }
//�������ĸ߳����� public static void ProfileGetRelatedSewerElevData(AxMapControl ppAxMapControl, IGeometricNetwork pGeoNetwork, IEnumNetEID pResultEdges, IEnumNetEID pResultJunctions) { try { //��ñ������Զ�Ӧ�������ٽ�� IArray pSewerElevArray = new ArrayClass(); IEIDHelper pEIDHelper = new EIDHelperClass(); pEIDHelper.GeometricNetwork = pGeoNetwork; pEIDHelper.ReturnFeatures = true; pEIDHelper.ReturnGeometries = true; pEIDHelper.PartialComplexEdgeGeometry = true; pEIDHelper.AddField("Component_Key2"); IEnumEIDInfo pEnumEIDInfo = pEIDHelper.CreateEnumEIDInfo(pResultEdges); //������������ص�������¼ pEnumEIDInfo.Reset(); IEIDInfo pEIDInfo = pEnumEIDInfo.Next(); IFeature pFeature = pEIDInfo.Feature; IGeometry pFeatGeo = pEIDInfo.Geometry; //�������л�ù�ϵ IEnumRelationshipClass pEnumRelationshipCls = pFeature.Class.get_RelationshipClasses(esriRelRole.esriRelRoleOrigin); pEnumRelationshipCls.Reset(); IRelationshipClass pRelationshipCls = pEnumRelationshipCls.Next(); //�����ȷ�Ĺ�ϵ�� string s = "SewerToMainline"; while (pRelationshipCls != null) { if (pRelationshipCls.ForwardPathLabel.ToUpper() == s.ToUpper()) break; else pRelationshipCls = pEnumRelationshipCls.Next(); } //��ѯ���ɹ�����ÿ������ص����ݣ������1-1�Ĺ�ϵ����ֻ����һ����¼ // because the arcs are ordered and directional, if the start node is an // fnode then get subsequent tnode's for the rest of the arcs, else if the // start node is a tnode, get subsequent fnode's. Related data has elev // attributes for up and down stream manhole elevs, so related to from and to node of arc. // get the first junction in the network trace results to determine if the //first junction is a from-node or a to-node for graphing sewer line elev if (pRelationshipCls != null) { ISet pMainlineRelatedSet; IRow pMainlineRow; IEIDHelper pEIDHelper2 = new EIDHelperClass(); pEIDHelper2.GeometricNetwork = pGeoNetwork; pEIDHelper2.ReturnFeatures = true; pEIDHelper2.ReturnGeometries = true; pEIDHelper2.PartialComplexEdgeGeometry = true; IEnumEIDInfo pEnumEIDInfo2 = pEIDHelper2.CreateEnumEIDInfo(pResultJunctions); pEnumEIDInfo2.Reset(); //pFeature is the first arc in the network trace results // check the junctions on the first arc to see which is the starting // junction, this determines which sewer elev attribute (ups_elev, dwn_elev) // will be used to calculate the sewer line profile IEdgeFeature pEdgeFeat = pFeature as IEdgeFeature; string strStartAttr; string strMHelevAttr; double lastelev = 0; int lastnodeEID; if (pEnumEIDInfo2.Next().EID == pEdgeFeat.FromJunctionEID) { // trace is in the direction of flow, flow goes down hill strStartAttr = "Ups_elev"; strMHelevAttr = "Dwn_elev"; } else { //trace is in the opposite direction of flow, flow goes up hill strStartAttr = "Dwn_elev"; strMHelevAttr = "Ups_elev"; } lastnodeEID = pEnumEIDInfo2.Next().EID; // create a polyline from the result junctions, make the polyline in the //direction of the trace, not in the direction of the original arcs/edges IPolyline pPolyline = new PolylineClass(); IPointCollection pPointColl = pPolyline as IPointCollection; pEnumEIDInfo2.Reset(); object missing = Type.Missing; for (int i = 0; i <= pEnumEIDInfo2.Count - 1; i++) { pPointColl.AddPoint(pEnumEIDInfo2.Next().Geometry as IPoint, ref missing, ref missing); } ISegmentCollection pSegColl = pPolyline as ISegmentCollection; //����� ITopologicalOperator pTopoOp = pPolyline as ITopologicalOperator; pTopoOp.Simplify(); pPolyline.SimplifyNetwork(); pPolyline.Densify(50, 0.01); pResultEdges.Reset(); pEnumEIDInfo2.Reset(); IPolyline pNewSegPolyline; IPolyline pPolyLineFeat; IRelationalOperator pRelOpFeat; ISegmentCollection pNewSegColl; ISegmentCollection pSegmentColl = pPolyline as ISegmentCollection; for (int i = 0; i <= pResultEdges.Count - 1; i++) { pMainlineRelatedSet = pRelationshipCls.GetObjectsRelatedToObject(pFeature); pMainlineRelatedSet.Reset(); pMainlineRow = pMainlineRelatedSet.Next() as IRow; pPolyLineFeat = pFeature.Shape as IPolyline; pRelOpFeat = pPolyLineFeat as IRelationalOperator; for (int j = 0; j <= pSegmentColl.SegmentCount - 1; j++) { pNewSegPolyline = new PolylineClass(); pNewSegColl = pNewSegPolyline as ISegmentCollection; pNewSegColl.AddSegment(pSegmentColl.get_Segment(j), ref missing, ref missing); if (pRelOpFeat.Contains(pNewSegPolyline as IGeometry)) { if (j == 0) { pSewerElevArray.Add(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strStartAttr))); lastelev = Convert.ToDouble(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr))); } else { if (lastelev == Convert.ToDouble(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr)))) { pSewerElevArray.Add(-99); } else { pSewerElevArray.Add(lastelev); lastelev = Convert.ToDouble(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr))); } } } } // get the next feature and check to see what direction it's going and //adjust the variables accordingly if (i < pResultEdges.Count - 1) { lastnodeEID = pEdgeFeat.ToJunctionEID; pFeature = pEnumEIDInfo.Next().Feature; pEdgeFeat = pFeature as IEdgeFeature; if (pEdgeFeat.FromJunctionEID == lastnodeEID) strMHelevAttr = "Dwn_elev"; else strMHelevAttr = "Ups_elev"; } else { pSewerElevArray.Add(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr))); } } ProfileCreateGraph(ppAxMapControl, pPolyline, pSewerElevArray); } } catch (Exception eX) { MessageBox.Show(eX.Message); } }
public void GetFlow(IMap pMap) { int num4; this.m_pPointcol = new MultipointClass(); this.m_eFlowDirection.Clear(); this.m_angle.Clear(); INetwork network = NetworkAnalyst.m_pAnalystGN.Network; IUtilityNetwork network2 = network as IUtilityNetwork; IEnumNetEID netEIDs = network.CreateNetBrowser(esriElementType.esriETEdge); IEnumNetEID teid2 = network.CreateNetBrowser(esriElementType.esriETJunction); netEIDs.Reset(); int count = netEIDs.Count; int num2 = teid2.Count; IEIDHelper helper = new EIDHelperClass { GeometricNetwork = NetworkAnalyst.m_pAnalystGN, OutputSpatialReference = pMap.SpatialReference, ReturnGeometries = true, ReturnFeatures = true }; IEnumEIDInfo info = helper.CreateEnumEIDInfo(teid2); int num3 = info.Count; teid2.Reset(); info.Reset(); IPointCollection points = new MultipointClass(); object before = Missing.Value; for (num4 = 0; num4 < num2; num4++) { IPoint inPoint = info.Next().Geometry as IPoint; points.AddPoint(inPoint, ref before, ref before); } info = null; info = helper.CreateEnumEIDInfo(netEIDs); num3 = info.Count; netEIDs.Reset(); info.Reset(); IList list = new ArrayList(); ILine line = new LineClass(); IList list2 = new ArrayList(); int num5 = 0; for (num4 = 0; num4 < count; num4++) { int edgeEID = netEIDs.Next(); this.m_eFlowDirection.Add(network2.GetFlowDirection(edgeEID)); IEIDInfo info2 = info.Next(); IGeometry geometry = info2.Geometry; IEdgeFeature feature = info2.Feature as IEdgeFeature; IPointCollection points2 = geometry as IPointCollection; int pointCount = points2.PointCount; IPoint other = new PointClass(); IPoint[] pointArray = new IPoint[pointCount]; IRelationalOperator @operator = points as IRelationalOperator; IPointCollection points3 = new MultipointClass(); int num8 = 0; for (int i = 0; i < pointCount; i++) { other = points2.get_Point(i); if (@operator.Contains(other)) { IPoint point3 = points2.get_Point(i); points3.AddPoint(point3, ref before, ref before); pointArray[i] = point3; } else { pointArray[i] = null; } } IPoint[] pointArray2 = new IPoint[pointCount]; num8 = points3.PointCount; int index = -1; if (num5 < (points3.PointCount - 1)) { for (int j = 0; j < pointCount; j++) { if (pointArray[j] != null) { index++; } if (index == num5) { index = j; break; } } IPoint point4 = new PointClass(); pointArray2[index] = pointArray[index]; pointArray2[index + 1] = points2.get_Point(index + 1); point4.X = (pointArray2[index].X + pointArray2[index + 1].X) / 2.0; point4.Y = (pointArray2[index].Y + pointArray2[index + 1].Y) / 2.0; this.m_pPointcol.AddPoint(point4, ref before, ref before); line.FromPoint = pointArray2[index]; line.ToPoint = pointArray2[index + 1]; this.m_angle.Add(line.Angle); num5++; if (num5 == (num8 - 1)) { num5 = 0; } } } this.ShowFlow(pMap as IActiveView); }
public static void pathToPolyline(IGeometricNetwork pGeometricNetwork,IActiveView pActiveView,IEnumNetEID pEnumNetEID_Edges) { try { IEIDHelper piEIDHelper=new EIDHelperClass(); piEIDHelper.GeometricNetwork=pGeometricNetwork; piEIDHelper.OutputSpatialReference=pActiveView.FocusMap.SpatialReference; piEIDHelper.ReturnFeatures=true; IPolyline mPolyline=new PolylineClass(); mPolyline.SpatialReference=pActiveView.FocusMap.SpatialReference; IEIDInfo ipEIDInfo; IEnumEIDInfo piEnumEIDInfo; IGeometry ipGeometry=null; piEnumEIDInfo=piEIDHelper.CreateEnumEIDInfo(pEnumNetEID_Edges); IGeometryCollection pGeoCollection=mPolyline as IGeometryCollection; piEnumEIDInfo.Reset(); object objMiss=Type.Missing; for(int ii=0;ii<piEnumEIDInfo.Count;ii++) { ipEIDInfo=piEnumEIDInfo.Next(); ipGeometry=ipEIDInfo.Feature.Shape; if(ipGeometry!=null) Utility.drawPolyline(pActiveView,ipGeometry as IPolyline); } //return ipGeometry as IPolyline; } catch(Exception e) { MessageBox.Show(e.Message); } finally { } }
private static Dictionary<IFeature, int> GetFeaturesFromNetEID(IGeometricNetwork geomNet, IEnumNetEIDBuilder enumEIDBuilder) { string fileName = "eidGeomLines.txt"; if (((IEnumNetEID)enumEIDBuilder).ElementType == esriElementType.esriETJunction) { fileName = "eidGeomPoints.txt"; } Dictionary<IFeature, int> featuresInPath = new Dictionary<IFeature, int>(); using (System.IO.StreamWriter sw = System.IO.File.CreateText("C:\\temp\\" + fileName)) { sw.Write("["); IEIDHelper eidHelper = new EIDHelperClass(); //eidHelper.AddField("OBJECTID"); //eidHelper.AddField("SHAPE"); eidHelper.ReturnGeometries = true; int multiplier = 1; if (((IEnumNetEID)enumEIDBuilder).ElementType == esriElementType.esriETEdge) { multiplier = -1; } eidHelper.ReturnFeatures = true; eidHelper.GeometricNetwork = geomNet; IEnumEIDInfo enumEIDInfo = eidHelper.CreateEnumEIDInfo(enumEIDBuilder as IEnumNetEID); enumEIDInfo.Reset(); for (int i = 0; i < enumEIDInfo.Count; i++) { IEIDInfo eidInfo = enumEIDInfo.Next(); try { IFeature fe = eidInfo.Feature; int eid = eidInfo.EID; featuresInPath.Add(fe, eidInfo.EID); sw.Write("["); sw.Write(eid * multiplier); sw.Write(","); sw.Write("["); if (fe.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) { #region Loop through the point collection of the polyline and write out to the file IPointCollection pc = fe.Shape as IPointCollection; for (int j = 0; j < pc.PointCount; j++) { sw.Write("["); sw.Write(pc.get_Point(j).X + "," + pc.get_Point(j).Y); sw.Write("]"); if (j + 1 < pc.PointCount) { sw.Write("],"); } } #endregion } else if (fe.Shape.GeometryType == esriGeometryType.esriGeometryPoint) { IPoint pnt = fe.Shape as IPoint; sw.Write(pnt.X.ToString() + "," + pnt.Y.ToString()); sw.Write("]"); } if (i + 1 < enumEIDInfo.Count) { sw.Write(",");//more geometries coming! } } catch { } } sw.Write("]"); // This closes off all the geoemtries sw.Close(); } return featuresInPath; }
/// <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); } }