protected override void OnClick() { // get the current network IUtilityNetwork utilNet = GetCurrentNetwork() as IUtilityNetwork; // create an edit operation enabling an undo for this operation m_editorExt.StartOperation(); // get a list of the current EIDs for edges in the network IEnumNetEID edgeEIDs = GetCurrentEIDs(esriElementType.esriETEdge); // set the flow direction for each edge in the network edgeEIDs.Reset(); for (int i = 0; i < edgeEIDs.Count; i++) { int edgeEID = edgeEIDs.Next(); utilNet.SetFlowDirection(edgeEID, esriFlowDirection.esriFDWithFlow); } // stop the edit operation, specifying a name for this operation m_editorExt.StopOperation("Set Flow Direction"); // refresh the display to update the flow direction arrows IActiveView mapView = ArcMap.Document.ActiveView; mapView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
protected override void OnUpdate() { // by default, disable the command Enabled = false; // if there is not a current edit session, then disable the command if (m_editorExt.EditState != esriEditState.esriStateEditing) { return; } // otherwise, check to see if the flow direction is properly set for each edge EID IUtilityNetwork utilNet = GetCurrentNetwork() as IUtilityNetwork; IEnumNetEID edgeEIDs = GetCurrentEIDs(esriElementType.esriETEdge); edgeEIDs.Reset(); for (int i = 0; i < edgeEIDs.Count; i++) { int edgeEID = edgeEIDs.Next(); esriFlowDirection flowDir = utilNet.GetFlowDirection(edgeEID); if (flowDir != esriFlowDirection.esriFDWithFlow) { // enable the command if the flow direction is not with the digitized direction Enabled = true; // we can return right now, since only one edge needs to have // incorrect flow direction in order to enable the command return; } } }
// // returns an enumeration of EIDs of the network elements of the given element type // private IEnumNetEID GetCurrentEIDs(esriElementType elementType) { INetwork net = GetCurrentNetwork(); IEnumNetEID eids = net.CreateNetBrowser(elementType); return(eids); }
private void method_6(IGeometricNetwork geometricNetwork) { INetwork network = geometricNetwork.Network; IUtilityNetwork utilityNetwork = (IUtilityNetwork)network; IEnumNetEID enumNetEID = network.CreateNetBrowser((esriElementType)2); IEIDHelper eIDHelperClass = new EIDHelper(); eIDHelperClass.GeometricNetwork = (geometricNetwork); eIDHelperClass.DisplayEnvelope = (null); eIDHelperClass.OutputSpatialReference = (null); eIDHelperClass.ReturnFeatures = (false); eIDHelperClass.ReturnGeometries = (true); eIDHelperClass.PartialComplexEdgeGeometry = (true); IEnumEIDInfo enumEIDInfo = eIDHelperClass.CreateEnumEIDInfo(enumNetEID); enumEIDInfo.Reset(); long num = (long)enumEIDInfo.Count; int num2 = 0; while ((long)num2 < num) { IEIDInfo iEIDInfo = enumEIDInfo.Next(); int eID = iEIDInfo.EID; IGeometry geometry = iEIDInfo.Geometry; esriFlowDirection esriFlowDirection = this.method_7(geometry); utilityNetwork.SetFlowDirection(eID, esriFlowDirection); num2++; } }
/// <summary> /// set edge and junction for results /// </summary> /// <param name="objectJson">object JsonObject</param> /// <param name="edgeEIDs">object IEnumNetEID for edge</param> /// <param name="junctionEIDs">object IEnumNetEID for junction</param> protected void SetResults(ref JsonObject objectJson, IEnumNetEID edgeEIDs, IEnumNetEID junctionEIDs) { if ((this.FlowElements == esriFlowElements.esriFEEdges) || (this.FlowElements == esriFlowElements.esriFEJunctionsAndEdges)) { if (edgeEIDs == null) { throw new GeometricNetworkException("No traced edges found"); } else { if (edgeEIDs.Count > this.MaxFeatures) { throw new GeometricNetworkException(edgeEIDs.Count.ToString(CultureInfo.InvariantCulture) + " features were traced which exceeds the limit of " + this.MaxFeatures); } } } if ((this.FlowElements == esriFlowElements.esriFEJunctions) || (this.FlowElements == esriFlowElements.esriFEJunctionsAndEdges)) { if (junctionEIDs == null) { throw new GeometricNetworkException("No traced junctions found"); } else { if (junctionEIDs.Count > this.MaxFeatures) { throw new GeometricNetworkException(junctionEIDs.Count.ToString(CultureInfo.InvariantCulture) + " features were traced which exceeds the limit of " + this.MaxFeatures); } } } if (this.FlowElements == esriFlowElements.esriFEEdges || this.FlowElements == esriFlowElements.esriFEJunctionsAndEdges) { if (edgeEIDs.Count == 0) { objectJson.AddArray("edges", (new List <JsonObject>()).ToArray()); } else { JsonObject[] featureSet; this.GetTrace(edgeEIDs, out featureSet); objectJson.AddArray("edges", featureSet); } } if (this.FlowElements == esriFlowElements.esriFEJunctions || this.FlowElements == esriFlowElements.esriFEJunctionsAndEdges) { if (junctionEIDs.Count == 0) { objectJson.AddArray("junctions", (new List <JsonObject>()).ToArray()); } else { JsonObject[] featureSet; this.GetTrace(junctionEIDs, out featureSet); objectJson.AddArray("junctions", featureSet); } } }
private void DrawTraceRsult(IEnumNetEID JunctionEIDs, IEnumNetEID EdgEIDs) { if (JunctionBarrierEIDs == null || EdgEIDs == null) { return; } INetElements netElements = m_GeometryNetwork.Network as INetElements; int userClssID = -1; int userID = -1; int userSubID = -1; int eid = -1; // IFeatureClass fteClss; IFeature feature; //设置管点和管线显示的Symbol ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Color = Method.Getcolor(255, 0, 0); simpleMarkerSymbol.Size = 6; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = Method.Getcolor(255, 0, 0); simpleLineSymbol.Width = 2; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; IElement element; //获取管点结果 for (int i = 0; i < JunctionEIDs.Count; i++) { eid = JunctionEIDs.Next(); netElements.QueryIDs(eid, esriElementType.esriETJunction, out userClssID, out userID, out userSubID); fteClss = GetFteClssByID(userClssID, this.Mapcontrol.Map); if (fteClss != null) { feature = fteClss.GetFeature(userID); element = new MarkerElementClass(); element.Geometry = feature.Shape; ((IMarkerElement)element).Symbol = simpleMarkerSymbol; ((IElementProperties)element).Name = "Result"; this.Mapcontrol.ActiveView.GraphicsContainer.AddElement(element, 0); } } //获取管线结果 for (int j = 0; j < EdgEIDs.Count; j++) { eid = EdgEIDs.Next(); netElements.QueryIDs(eid, esriElementType.esriETEdge, out userClssID, out userID, out userSubID); fteClss = GetFteClssByID(userClssID, this.Mapcontrol.Map); if (fteClss != null) { feature = fteClss.GetFeature(userID); element = new LineElementClass(); element.Geometry = feature.Shape; ((ILineElement )element).Symbol = simpleLineSymbol; ((IElementProperties)element).Name = "Result"; this.Mapcontrol.ActiveView.GraphicsContainer.AddElement(element, 0); } } }
/// <summary> /// Converts an Esri enumerable interface to a DotNet IEnumerable. /// </summary> /// <param name="esriEnum">An enumerable Esri interface.</param> /// <returns>The adapted dotnet enumeration.</returns> public static IEnumerable <int> Enumerate(this IEnumNetEID esriEnum) { esriEnum.Reset(); for (int item = esriEnum.Next(); item > 0; item = esriEnum.Next()) { yield return(item); } }
//关闭工作空间 private void CloseWorkspace() { m_ipGeometricNetwork = null; m_ipPoints = null; m_ipPointToEID = null; m_ipEnumNetEID_Junctions = null; m_ipEnumNetEID_Edges = null; m_ipPolyline = null; }
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; } }
private Dictionary <IPoint, int> _ExtractUpstreamPipeEnds() { int iInletClassID = _inletClass.FeatureClassID; INetwork network = _geometricNetwork.Network; INetElements netElements = network as INetElements; INetTopology netTopology = network as INetTopology; Dictionary <IPoint, int> endPoints = new Dictionary <IPoint, int>(); IEnumNetEID netEnum = network.CreateNetBrowser(esriElementType.esriETJunction); int junctionCount = netEnum.Count; int classId, userId, subId, edgeId; bool towardJunction; int junctionId = -1; for (int j = 0; j < junctionCount; j++) { junctionId = netEnum.Next(); netElements.QueryIDs(junctionId, esriElementType.esriETJunction, out classId, out userId, out subId); if (classId != iInletClassID) { bool disabled = false; if (_excludeDisabled) { disabled = _IsDisabled(junctionId, esriElementType.esriETJunction, netElements); } if (!(_excludeDisabled && disabled)) { int edgeCount = netTopology.GetAdjacentEdgeCount(junctionId); bool isUpstreamEnd = edgeCount > 0; // initializing only (zero edge count always excluded) for (int e = 0; e < edgeCount; e++) { netTopology.GetAdjacentEdge(junctionId, e, out edgeId, out towardJunction); if (towardJunction) { isUpstreamEnd = false; break; } } if (isUpstreamEnd) { endPoints.Add(_geometricNetwork.get_GeometryForJunctionEID(junctionId) as IPoint, junctionId); } } } } return(endPoints); }
public void SetResults(IEnumNetEID edgeEnumNetEID, IEnumNetEID juncEnumNetEID, bool asSelection, INetworkAnalysisExt netAnalExt, Color namedColor) { INetworkAnalysisExtResults netAnalResults = (INetworkAnalysisExtResults)_netAnalExt; IRgbColor rgbColor = new RgbColorClass(); rgbColor.Red = namedColor.R; rgbColor.Blue = namedColor.B; rgbColor.Green = namedColor.G; netAnalResults.ResultsAsSelection = asSelection; netAnalResults.DrawComplex = true; INetworkAnalysisExtResultColor netAnalColor = (INetworkAnalysisExtResultColor)netAnalExt; netAnalColor.Color = rgbColor; netAnalResults.SetResults(juncEnumNetEID, edgeEnumNetEID); }
/// <summary> /// Creates an <see cref="IEnumerable{T}" /> from an <see cref="IEnumNetEID" /> /// </summary> /// <param name="source">An <see cref="IEnumNetEID" /> to create an <see cref="IEnumerable{T}" /> from.</param> /// <returns>An <see cref="IEnumerable{T}" /> that contains the datasets from the input source.</returns> public static IEnumerable <int> AsEnumerable(this IEnumNetEID source) { if (source != null) { source.Reset(); int eid = source.Next(); while (eid != 0) { yield return(eid); eid = source.Next(); } } }
private void method_4(INetwork network) { IUtilityNetwork utilityNetwork = (IUtilityNetwork)network; IEnumNetEID enumNetEID = network.CreateNetBrowser((esriElementType)2); enumNetEID.Reset(); long num = (long)enumNetEID.Count; int num2 = 0; while ((long)num2 < num) { int num3 = enumNetEID.Next(); utilityNetwork.SetFlowDirection(num3, (esriFlowDirection)1); num2++; } }
/// <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); }
private void method_5(IGeometricNetwork geometricNetwork) { INetwork network = geometricNetwork.Network; IUtilityNetwork utilityNetwork = (IUtilityNetwork)network; IEnumNetEID enumNetEID = network.CreateNetBrowser((esriElementType)2); IEIDHelper eIDHelperClass = new EIDHelper(); eIDHelperClass.GeometricNetwork = (geometricNetwork); eIDHelperClass.DisplayEnvelope = (null); eIDHelperClass.OutputSpatialReference = (null); eIDHelperClass.ReturnFeatures = (true); eIDHelperClass.ReturnGeometries = (true); eIDHelperClass.PartialComplexEdgeGeometry = (true); IEnumEIDInfo enumEIDInfo = eIDHelperClass.CreateEnumEIDInfo(enumNetEID); enumEIDInfo.Reset(); long num = (long)enumEIDInfo.Count; int num2 = 0; while ((long)num2 < num) { IEIDInfo iEIDInfo = enumEIDInfo.Next(); int eID = iEIDInfo.EID; IFeature feature = iEIDInfo.Feature; int num3 = feature.Fields.FindField("流向"); if (num3 < 0) { utilityNetwork.SetFlowDirection(eID, (esriFlowDirection)1); } if (Convert.ToBoolean(feature.get_Value(num3))) { utilityNetwork.SetFlowDirection(eID, (esriFlowDirection)2); } else { utilityNetwork.SetFlowDirection(eID, (esriFlowDirection)1); } num2++; } }
//��˷�ٲ��ҹ����漰�ĵؿ� public static void UpStreamFindParcels(AxMapControl ppAxMapControl, IEnumNetEID pEnumResultEdges, IGeometricNetwork pGeoNetwork) { try { IFeatureLayer pFeatLayerSewerLines = FindFeatLayer("Sewer Lines", ppAxMapControl); IFeatureLayer pFeatLayerParcels = FindFeatLayer("Parcels", ppAxMapControl); //����ѡ���Sewer�������д������ΰ� IGeometryCollection pGeomBag = new GeometryBagClass(); object missing = Type.Missing; int lEID; int iUserClassID; int iUserID; int iUserSubID; INetElements pNetElements = pGeoNetwork.Network as INetElements; pEnumResultEdges.Reset(); IFeature pFeature; for (int j = 0; j <= pEnumResultEdges.Count - 1; j++) { lEID = pEnumResultEdges.Next(); pNetElements.QueryIDs(lEID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID); pFeature = pFeatLayerSewerLines.FeatureClass.GetFeature(iUserID); pGeomBag.AddGeometry(pFeature.Shape, ref missing, ref missing); // MessageBox.Show(iUserClassID.ToString()+","+iUserID.ToString()+","+iUserSubID.ToString()); } //���пռ����˵��Ӳ��������ڲ��ҵؿ���Ϣ ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = pGeomBag as IGeometry; pSpatialFilter.GeometryField = "Shape"; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial; //��ý��浽�ĵؿ���Ϣ IFeatureCursor pFeatCursor = pFeatLayerParcels.FeatureClass.Search(pSpatialFilter, false); //���ӱ�ѡ��ĵؿ����ݵ���ͼ��ͼ��ͼ�������� ICompositeGraphicsLayer pComGraphicLayer = new CompositeGraphicsLayerClass(); ILayer pLayer = pComGraphicLayer as ILayer; pLayer.Name = "��Ӱ��ĵؿ�"; IGraphicsContainer pGraphicContainer = pComGraphicLayer as IGraphicsContainer; //������ѡ��ĵؿ鵽ͼ�������� ISimpleFillSymbol pSymFill = new SimpleFillSymbolClass(); IFillSymbol pFillSymbol = pSymFill as IFillSymbol; IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 0; pRgbColor.Green = 200; pRgbColor.Blue = 100; pFillSymbol.Color = pRgbColor as IColor; ICartographicLineSymbol pCartoLine = new CartographicLineSymbolClass(); IRgbColor pRgbColor2 = new RgbColorClass(); pRgbColor2.Red = 100; pRgbColor2.Green = 200; pRgbColor2.Blue = 100; pCartoLine.Width = 2; pCartoLine.Color = pRgbColor2 as IColor; pFillSymbol.Outline = pCartoLine; //����������еؿ����������� IArray pFeatArray = new ArrayClass(); pFeature = pFeatCursor.NextFeature(); while (pFeature != null) { IElement pPolyElement = new PolygonElementClass(); IFillShapeElement pFillShapeElement = pPolyElement as IFillShapeElement; pPolyElement.Geometry = pFeature.Shape; pFillShapeElement.Symbol = pFillSymbol; pGraphicContainer.AddElement(pPolyElement, 0); pFeatArray.Add(pFeature); pFeature = pFeatCursor.NextFeature(); } ppAxMapControl.AddLayer(pGraphicContainer as ILayer); ppAxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //ma //frmUpstreamCreateOwnerList frmUpstreamCreateOwnerList1 = new frmUpstreamCreateOwnerList(ppAxMapControl,pFeatLayerParcels, pFeatArray); //frmUpstreamCreateOwnerList1.Show(); } catch (Exception eX) { MessageBox.Show(eX.Message); } }
void ITraceTask.OnTraceExecution() { // prepare the network solver ITraceFlowSolverGEN tfs = UTIL_coreTraceSetup(); if (tfs == null) return; // perform the trace task IEnumNetEID resultJuncs, resultEdges; ITraceTasks traceTasks = m_utilNetExt as ITraceTasks; esriFlowElements flowElements = traceTasks.TraceFlowElements; if (traceTasks.TraceEnds) // find the features stopping the trace tfs.FindFlowEndElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges); else // return the traced features tfs.FindFlowElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges); // copy the results to the class level INetworkAnalysisExt nax = m_utilNetExt as INetworkAnalysisExt; if (resultJuncs == null) { // junctions were not returned -- create an empty enumeration IEnumNetEIDBuilder eidBuilder = new EnumNetEIDArrayClass(); eidBuilder.Network = nax.CurrentNetwork.Network; eidBuilder.ElementType = esriElementType.esriETJunction; m_resultJunctions = eidBuilder as IEnumNetEID; } else { m_resultJunctions = resultJuncs; } if (resultEdges == null) { // edges were not returned -- create an empty enumeration IEnumNetEIDBuilder eidBuilder = new EnumNetEIDArrayClass(); eidBuilder.Network = nax.CurrentNetwork.Network; eidBuilder.ElementType = esriElementType.esriETEdge; m_resultEdges = eidBuilder as IEnumNetEID; } else { m_resultEdges = resultEdges; } // update the extension with the results INetworkAnalysisExtResults naxResults = m_utilNetExt as INetworkAnalysisExtResults; naxResults.ClearResults(); // first remove the old results if (naxResults.ResultsAsSelection) naxResults.CreateSelection(resultJuncs, resultEdges); else { naxResults.SetResults(resultJuncs, resultEdges); } }
/// <summary> /// Get list EIDInfos by FeatureClass /// </summary> /// <param name="featureClassId">Id FeatureClass</param> /// <param name="junctionEIDs">object junctionEIDs</param> /// <param name="eidHelper">object eidHelper</param> /// <returns>List of IEIDInfo</returns> internal static List <IEIDInfo> GetEIDInfoListByFeatureClass(int featureClassId, IEnumNetEID junctionEIDs, IEIDHelper eidHelper) { List <IEIDInfo> outputEIDInfoHT = new List <IEIDInfo>(); IEnumEIDInfo allEnumEidInfo = eidHelper.CreateEnumEIDInfo(junctionEIDs); IEIDInfo eidInfo = allEnumEidInfo.Next(); while (eidInfo != null) { if (eidInfo.Feature.Class.ObjectClassID == featureClassId) { outputEIDInfoHT.Add(eidInfo); } eidInfo = allEnumEidInfo.Next(); } return(outputEIDInfoHT); }
//�������ĸ߳����� 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); } }
void ITraceTask.OnTraceExecution() { // prepare the network solver ITraceFlowSolverGEN tfs = UTIL_coreTraceSetup(); if (tfs == null) { return; } // perform the trace task IEnumNetEID resultJuncs, resultEdges; ITraceTasks traceTasks = m_utilNetExt as ITraceTasks; esriFlowElements flowElements = traceTasks.TraceFlowElements; if (traceTasks.TraceEnds) { // find the features stopping the trace tfs.FindFlowEndElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges); } else { // return the traced features tfs.FindFlowElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges); } // copy the results to the class level INetworkAnalysisExt nax = m_utilNetExt as INetworkAnalysisExt; if (resultJuncs == null) { // junctions were not returned -- create an empty enumeration IEnumNetEIDBuilder eidBuilder = new EnumNetEIDArrayClass(); eidBuilder.Network = nax.CurrentNetwork.Network; eidBuilder.ElementType = esriElementType.esriETJunction; m_resultJunctions = eidBuilder as IEnumNetEID; } else { m_resultJunctions = resultJuncs; } if (resultEdges == null) { // edges were not returned -- create an empty enumeration IEnumNetEIDBuilder eidBuilder = new EnumNetEIDArrayClass(); eidBuilder.Network = nax.CurrentNetwork.Network; eidBuilder.ElementType = esriElementType.esriETEdge; m_resultEdges = eidBuilder as IEnumNetEID; } else { m_resultEdges = resultEdges; } // update the extension with the results INetworkAnalysisExtResults naxResults = m_utilNetExt as INetworkAnalysisExtResults; naxResults.ClearResults(); // first remove the old results if (naxResults.ResultsAsSelection) { naxResults.CreateSelection(resultJuncs, resultEdges); } else { naxResults.SetResults(resultJuncs, resultEdges); } }
/// <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)); }
public static string TracePath(double[] Xs, double[] Ys, string GeoNetName, IApplication app, IMap map, bool traceIndeterminate, double snapTol, bool selectEdges, out IEnumNetEID juncEIDs, out IEnumNetEID edgeEIDs, out IGeometricNetwork gn) { gn = null; juncEIDs = null; edgeEIDs = null; List<INetFlag> pNetFlags = null; IFlagDisplay pFlagDisplay = null; IJunctionFlag[] junctionFlags = null; IEdgeFlag[] edgeFlags = null; ITraceFlowSolverGEN traceFlowSolver = null; List<IEdgeFlag> pEdgeFlags = null; List<IJunctionFlag> pJunctionFlags = null; INetElementBarriers pEdgeElementBarriers; INetElementBarriers pJunctionElementBarriers; ISelectionSetBarriers pSelectionSetBarriers; List<IGeometricNetwork> gnList = null; INetworkAnalysisExt pNetAnalysisExt = null; UID pID = null; try { gnList = Globals.GetGeometricNetworks(ref map); if (gnList == null) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_17a")); return ""; } int gnIdx = -1; gnIdx = Globals.GetGeometricNetwork(ref gnList, GeoNetName); if (gnIdx != -1) { gn = (IGeometricNetwork)gnList[gnIdx]; } pNetFlags = new List<INetFlag>(); // INetFlag[] netFlags = new INetFlag[Xs.Length]; for (int i = 0; i < Xs.Length; i++) { IPoint snappedPoint = null; int EID = -1; if (gn == null) { pNetFlags.Add(Globals.GetJunctionFlag(Xs[i], Ys[i], ref map, ref gnList, snapTol, ref gnIdx, out snappedPoint, out EID, out pFlagDisplay, true) as INetFlag); //Set network to trace if (gnIdx > -1) gn = gnList[gnIdx] as IGeometricNetwork; } else { pNetFlags.Add(Globals.GetJunctionFlagWithGN(Xs[i], Ys[i], ref map, ref gn, ref snapTol, out snappedPoint, out EID, out pFlagDisplay, true) as INetFlag); } } if (gn == null || pNetFlags.Count < 1) { return (A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_17b")); } if (app != null) { pID = new UID(); pID.Value = "esriEditorExt.UtilityNetworkAnalysisExt"; pNetAnalysisExt = (INetworkAnalysisExt)app.FindExtensionByCLSID(pID); Globals.SetCurrentNetwork(ref pNetAnalysisExt, ref gn); traceFlowSolver = Globals.CreateTraceFlowSolverFromToolbar(ref pNetAnalysisExt, out pEdgeFlags, out pJunctionFlags, out pEdgeElementBarriers, out pJunctionElementBarriers, out pSelectionSetBarriers) as ITraceFlowSolverGEN; } else { traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = gn.Network; } traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate; 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) //{ // pNetFlags.Add((INetFlag)startNetFlag); //} Globals.AddFlagsToTraceSolver(pNetFlags.ToArray(), ref traceFlowSolver, out junctionFlags, out edgeFlags); int intCount = 1; System.Object[] segCosts = new System.Object[1]; segCosts[0] = new System.Object(); traceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinMax, out juncEIDs, out edgeEIDs, intCount, ref segCosts); //Select junction features map.ClearSelection(); IJunctionFlag[] junctionFlag = null; Globals.SelectJunctions(ref map, ref gn, ref juncEIDs, ref junctionFlag, "", "", "", true); if (selectEdges) Globals.SelectEdges(ref map, ref gn, ref edgeEIDs); edgeEIDs.Reset(); //Draw edge graphics IEnvelope env = Globals.DrawEdges(ref map, ref gn, ref edgeEIDs); return edgeEIDs.Count.ToString(); } catch (Exception Ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_17a") + "\n" + Ex.Message); return ""; } }
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; } }
private void CloseWorkspace() { m_ipGeometricNetwork = null; m_ipPoints = null; m_ipPointToEID = null; m_ipEnumNetEID_Junctions = null; m_ipEnumNetEID_Edges = null; m_ipPolyline = null; }
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> /// operation solve trace /// </summary> /// <returns>solve trace</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)); if (this.barrierNotFound.Count > 0) { error.AddArray("barriersNotFound", Helper.GetListJsonObjects(this.barrierNotFound)); } return(error); } } ITraceFlowSolverGEN traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver netSolver = traceFlowSolver as INetSolver; INetwork network = this.geometricNetwork.Network; netSolver.SourceNetwork = network; // flag origin this.SetFlagsOrigin(ref traceFlowSolver); // barrier this.SetBarriers(ref traceFlowSolver); // set disabled layers foreach (int i in this.DisableLayers) { netSolver.DisableElementClass(i); } // set weight this.SetWeights(ref traceFlowSolver); if ((this.TraceSolverType != TraceSolverType.FindCircuits) && (this.TraceSolverType != TraceSolverType.FindCommonAncestors)) { // The TraceIndeterminateFlow property affects the trace results of trace solvers whose FlowMethod parameter is esriFMUpstream or esriFMDownstream if ((this.FlowMethod == esriFlowMethod.esriFMDownstream) || (this.FlowMethod == esriFlowMethod.esriFMUpstream)) { traceFlowSolver.TraceIndeterminateFlow = this.TraceIndeterminateFlow; } } IEnumNetEID junctionEIDs = null; IEnumNetEID edgeEIDs = null; object totalCost; int count; object[] segmentCosts; JsonObject objectJson = new JsonObject(); switch (this.TraceSolverType) { case TraceSolverType.FindAccumulation: traceFlowSolver.FindAccumulation(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs, out totalCost); objectJson.AddDouble("totalCost", (double)totalCost); break; case TraceSolverType.FindCircuits: traceFlowSolver.FindCircuits(this.FlowElements, out junctionEIDs, out edgeEIDs); break; case TraceSolverType.FindCommonAncestors: traceFlowSolver.FindCommonAncestors(this.FlowElements, out junctionEIDs, out edgeEIDs); break; case TraceSolverType.FindFlowElements: traceFlowSolver.FindFlowElements(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs); break; case TraceSolverType.FindFlowEndElements: traceFlowSolver.FindFlowEndElements(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs); break; case TraceSolverType.FindFlowUnreachedElements: traceFlowSolver.FindFlowUnreachedElements(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs); break; case TraceSolverType.FindPath: count = Math.Max(this.junctionFlags.Length, this.edgeFlags.Length); if (count < 2) { throw new GeometricNetworkException("Edge or junction found < 2!"); } --count; segmentCosts = new object[count]; traceFlowSolver.FindPath(this.FlowMethod, this.ShortestPathObjFn, out junctionEIDs, out edgeEIDs, count, ref segmentCosts); objectJson.AddArray("segmentCosts", segmentCosts); break; case TraceSolverType.FindSource: count = this.junctionFlags.Length + this.edgeFlags.Length; segmentCosts = new object[count]; traceFlowSolver.FindSource(this.FlowMethod, this.ShortestPathObjFn, out junctionEIDs, out edgeEIDs, count, ref segmentCosts); objectJson.AddArray("segmentCosts", segmentCosts); break; case TraceSolverType.FindLongest: // get end junctions in upstream IEnumNetEID junctionEIDsFindLongest = null; IEnumNetEID edgeEIDsFindLongest = null; traceFlowSolver.FindFlowEndElements(esriFlowMethod.esriFMUpstream, esriFlowElements.esriFEJunctions, out junctionEIDsFindLongest, out edgeEIDsFindLongest); int? eidLongest = null; double eidLongestLenght = double.MinValue; if (junctionEIDsFindLongest.Count > 0) { double eidLongestLenghtCurrent = double.NaN; for (int i = 0; i < junctionEIDsFindLongest.Count; i++) { int netEIDCurrent = junctionEIDsFindLongest.Next(); object[] segmentLenghts = new object[1]; IEnumNetEID junctionEIDsLongest = null; IEnumNetEID edgeEIDsLongest = null; INetFlag netFlag = new JunctionFlagClass(); INetElements netElements = this.geometricNetwork.Network as INetElements; int featureClassID, featureID, subID; netElements.QueryIDs(netEIDCurrent, esriElementType.esriETJunction, out featureClassID, out featureID, out subID); netFlag.UserClassID = featureClassID; netFlag.UserID = featureID; netFlag.UserSubID = subID; IJunctionFlag[] junctionFlags = new IJunctionFlag[] { this.junctionFlags[0], netFlag as IJunctionFlag }; traceFlowSolver.PutJunctionOrigins(ref junctionFlags); traceFlowSolver.FindPath(esriFlowMethod.esriFMUpstream, esriShortestPathObjFn.esriSPObjFnMinMax, out junctionEIDsLongest, out edgeEIDsLongest, 1, ref segmentLenghts); if (segmentLenghts[0] != null) { eidLongestLenghtCurrent = Convert.ToDouble(segmentLenghts[0]); if (eidLongestLenghtCurrent > eidLongestLenght) { eidLongestLenght = eidLongestLenghtCurrent; eidLongest = netEIDCurrent; edgeEIDs = edgeEIDsLongest; junctionEIDs = junctionEIDsLongest; } } } } else { throw new GeometricNetworkException("Junction end not found!"); } if (eidLongest.HasValue) { objectJson.AddDouble("totalCost", eidLongestLenght); } else { throw new GeometricNetworkException("EID longest not found!"); } break; default: throw new GeometricNetworkException("Trace solver type not found"); } this.SetResults(ref objectJson, edgeEIDs, junctionEIDs); objectJson.AddArray("flagsNotFound", Helper.GetListJsonObjects(this.flagNotFound)); objectJson.AddArray("barriersNotFound", Helper.GetListJsonObjects(this.barrierNotFound)); return(objectJson); } catch (Exception e) { return((new ObjectError(e.Message)).ToJsonObject()); } }
public static void ClearResult() { m_ipPolyline = null; m_ipEnumNetEID_Edges = null; m_ipEnumNetEID_Junctions = null; }
////几何网络 //private IGeometricNetwork mGeometricNetwork; ////给定点的集合 //private IPointCollection mPointCollection; ////获取给定点最近的Network元素 //private IPointToEID mPointToEID; ////返回结果变量 //private IEnumNetEID mEnumNetEID_Junctions; //private IEnumNetEID mEnumNetEID_Edges; //private double mdblPathCost; /// <summary> /// 实现路径分析 /// </summary> /// <param name="weightName">路径权重字段</param> public void SolvePath(string weightName, IGeometricNetwork mGeometricNetwork, IPointCollection mPointCollection, IPointToEID mPointToEID, out IEnumNetEID mEnumNetEID_Junctions, out IEnumNetEID mEnumNetEID_Edges, out double mdblPathCost) { //创建ITraceFlowSolverGEN ITraceFlowSolverGEN pTraceFlowSolverGEN = new TraceFlowSolverClass(); INetSolver pNetSolver = pTraceFlowSolverGEN as INetSolver; //初始化用于路径计算的Network INetwork pNetWork = mGeometricNetwork.Network; pNetSolver.SourceNetwork = pNetWork; //获取分析经过的点的个数 int intCount = mPointCollection.PointCount; if (intCount < 1) { MessageBox.Show("未获取到车辆点或目标点!"); } INetFlag pNetFlag; //用于存储路径计算得到的边 IEdgeFlag[] pEdgeFlags = new IEdgeFlag[intCount]; IPoint pEdgePoint = new PointClass(); int intEdgeEID; IPoint pFoundEdgePoint; double dblEdgePercent; //用于获取几何网络元素的UserID, UserClassID,UserSubID INetElements pNetElements = pNetWork as INetElements; int intEdgeUserClassID; int intEdgeUserID; int intEdgeUserSubID; for (int i = 0; i < intCount; i++) { pNetFlag = new EdgeFlagClass(); //获取用户点击点 pEdgePoint = mPointCollection.get_Point(i); //获取距离用户点击点最近的边 mPointToEID.GetNearestEdge(pEdgePoint, out intEdgeEID, out pFoundEdgePoint, out dblEdgePercent); if (intEdgeEID <= 0) { continue; } //根据得到的边查询对应的几何网络中的元素UserID, UserClassID,UserSubID pNetElements.QueryIDs(intEdgeEID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdgeUserID, out intEdgeUserSubID); if (intEdgeUserClassID <= 0 || intEdgeUserID <= 0) { continue; } pNetFlag.UserClassID = intEdgeUserClassID; pNetFlag.UserID = intEdgeUserID; pNetFlag.UserSubID = intEdgeUserSubID; pEdgeFlags[i] = pNetFlag as IEdgeFlag; } //设置路径求解的边 pTraceFlowSolverGEN.PutEdgeOrigins(ref pEdgeFlags); //路径计算权重 INetSchema pNetSchema = pNetWork as INetSchema; INetWeight pNetWeight = pNetSchema.get_WeightByName(weightName); if (pNetWeight == null) { MessageBox.Show("权重设置有误!"); } //设置权重,这里双向的权重设为一致 INetSolverWeights pNetSolverWeights = pTraceFlowSolverGEN as INetSolverWeights; pNetSolverWeights.ToFromEdgeWeight = pNetWeight; pNetSolverWeights.FromToEdgeWeight = pNetWeight; object[] arrResults = new object[intCount - 1]; //执行路径计算 pTraceFlowSolverGEN.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out mEnumNetEID_Junctions, out mEnumNetEID_Edges, intCount - 1, ref arrResults); //获取路径计算总代价(cost) mdblPathCost = 0; for (int i = 0; i < intCount - 1; i++) { mdblPathCost += (double)arrResults[i]; } }
/// <summary> /// 路径分析结果到几何要素的转换 /// </summary> /// <param name="pMap">当前地图 获取空间参考</param> /// <returns></returns> public IPolyline PathToPolyLine(IMap pMap, IGeometricNetwork mGeometricNetwork, IEnumNetEID mEnumNetEID_Edges) { IPolyline pPolyLine = new PolylineClass(); IGeometryCollection pNewGeometryCollection = pPolyLine as IGeometryCollection; if (mEnumNetEID_Edges == null) { return(null); } IEIDHelper pEIDHelper = new EIDHelperClass(); //获取几何网络 pEIDHelper.GeometricNetwork = mGeometricNetwork; //获取地图空间参考 ISpatialReference pSpatialReference = pMap.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); }
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 void SetButton_Click(object obj, EventArgs eventArgs) { int count = this.listJunctionFlag.Count; int count2 = this.listEdgeFlag.Count; int count3 = this.listJunctionBarrier.Count; int count4 = this.listEdgeBarrier.Count; if (count < 1 && count2 < 1) { MessageBox.Show("请用户选择要分析的点或线!"); } else { IEdgeFlag[] array = new EdgeFlag[count2]; IJunctionFlag[] array2 = new JunctionFlag[count]; INetwork network = null; INetworkClass networkClass = null; if (count > 0) { for (int i = 0; i < count; i++) { IFeature feature = this.listJunctionFlag[i]; networkClass = (feature.Class as INetworkClass); network = networkClass.GeometricNetwork.Network; INetElements netElements = network as INetElements; INetFlag netFlag = new JunctionFlag() as INetFlag; ISimpleJunctionFeature simpleJunctionFeature = feature as ISimpleJunctionFeature; int userClassID; int userID; int userSubID; netElements.QueryIDs(simpleJunctionFeature.EID, (esriElementType)1, out userClassID, out userID, out userSubID); netFlag.UserClassID = (userClassID); netFlag.UserID = (userID); netFlag.UserSubID = (userSubID); IJunctionFlag junctionFlag = netFlag as IJunctionFlag; array2[i] = junctionFlag; } } if (count2 > 0) { for (int j = 0; j < count2; j++) { IFeature feature2 = this.listEdgeFlag[j]; networkClass = (feature2.Class as INetworkClass); network = networkClass.GeometricNetwork.Network; INetElements netElements2 = network as INetElements; INetFlag netFlag2 = new EdgeFlag() as INetFlag; ISimpleEdgeFeature simpleEdgeFeature = feature2 as ISimpleEdgeFeature; int userClassID2; int userID2; int userSubID2; netElements2.QueryIDs(simpleEdgeFeature.EID, (esriElementType)2, out userClassID2, out userID2, out userSubID2); netFlag2.UserClassID = (userClassID2); netFlag2.UserID = (userID2); netFlag2.UserSubID = (userSubID2); IEdgeFlag edgeFlag = netFlag2 as IEdgeFlag; array[j] = edgeFlag; } } ITraceFlowSolverGEN traceFlowSolverGEN = new TraceFlowSolver() as ITraceFlowSolverGEN; INetSolver netSolver = traceFlowSolverGEN as INetSolver; INetElementBarriersGEN netElementBarriersGEN = new NetElementBarriers(); netElementBarriersGEN.Network = (network); netElementBarriersGEN.ElementType = (esriElementType)(1); int[] array3 = new int[count3]; int num = 0; if (count3 > 0) { for (int k = 0; k < count3; k++) { IFeature feature3 = this.listJunctionBarrier[k]; networkClass = (feature3.Class as INetworkClass); network = networkClass.GeometricNetwork.Network; INetElements netElements3 = network as INetElements; new EdgeFlag(); ISimpleJunctionFeature simpleJunctionFeature2 = feature3 as ISimpleJunctionFeature; int num2; int num3; netElements3.QueryIDs(simpleJunctionFeature2.EID, (esriElementType)1, out num, out num2, out num3); array3[k] = num2; } netElementBarriersGEN.SetBarriers(num, ref array3); netSolver.set_ElementBarriers((esriElementType)1, (INetElementBarriers)netElementBarriersGEN); } INetElementBarriersGEN netElementBarriersGEN2 = new NetElementBarriers(); netElementBarriersGEN2.Network = (network); netElementBarriersGEN2.ElementType = (esriElementType)(2); int[] array4 = new int[count4]; if (count4 > 0) { for (int l = 0; l < count4; l++) { IFeature feature4 = this.listEdgeBarrier[l]; networkClass = (feature4.Class as INetworkClass); network = networkClass.GeometricNetwork.Network; INetElements netElements4 = network as INetElements; new EdgeFlag(); ISimpleEdgeFeature simpleEdgeFeature2 = feature4 as ISimpleEdgeFeature; int num4; int num5; netElements4.QueryIDs(simpleEdgeFeature2.EID, (esriElementType)2, out num, out num4, out num5); array4[l] = num4; } netElementBarriersGEN2.SetBarriers(num, ref array4); netSolver.set_ElementBarriers((esriElementType)2, (INetElementBarriers)netElementBarriersGEN2); } netSolver.SourceNetwork = (network); if (count > 0) { traceFlowSolverGEN.PutJunctionOrigins(ref array2); } if (count2 > 0) { traceFlowSolverGEN.PutEdgeOrigins(ref array); } IEnumNetEID enumNetEID = null; IEnumNetEID enumNetEID2 = null; object[] array5 = new object[1]; if (this.WayCom.SelectedIndex == 0) { traceFlowSolverGEN.FindSource(0, (esriShortestPathObjFn)1, out enumNetEID, out enumNetEID2, count + count2, ref array5); } if (this.WayCom.SelectedIndex == 1) { traceFlowSolverGEN.FindSource((esriFlowMethod)1, (esriShortestPathObjFn)1, out enumNetEID, out enumNetEID2, count + count2, ref array5); } IPolyline polyline = new Polyline() as IPolyline; IGeometryCollection geometryCollection = polyline as IGeometryCollection; ISpatialReference spatialReference = this.m_iApp.FocusMap.SpatialReference; IEIDHelper iEIDHelper = new EIDHelper(); iEIDHelper.GeometricNetwork = (networkClass.GeometricNetwork); iEIDHelper.OutputSpatialReference = (spatialReference); iEIDHelper.ReturnGeometries = (true); iEIDHelper.ReturnFeatures = (true); int selectedIndex = this.LayerCom.SelectedIndex; if (selectedIndex >= 0 && this.MapControl != null) { this.LayerCom.SelectedItem.ToString(); IFeatureLayer ifeatureLayer_ = ((TrackingAnalyForm.LayerInfo) this.LayerCom.SelectedItem)._layer; if (ifeatureLayer_ != null) { IFeatureSelection featureSelection = (IFeatureSelection)ifeatureLayer_; featureSelection.Clear(); if (enumNetEID2 != null) { IEnumEIDInfo enumEIDInfo = iEIDHelper.CreateEnumEIDInfo(enumNetEID2); int count5 = enumEIDInfo.Count; enumEIDInfo.Reset(); for (int m = 0; m < count5; m++) { IEIDInfo iEIDInfo = enumEIDInfo.Next(); featureSelection.Add(iEIDInfo.Feature); IGeometry geometry = iEIDInfo.Geometry; geometryCollection.AddGeometryCollection(geometry as IGeometryCollection); } } featureSelection.SelectionSet.Refresh(); IActiveView activeView = this.m_iApp.ActiveView; activeView.Refresh(); CMapOperator.ShowFeatureWithWink(this.m_iApp.ActiveView.ScreenDisplay, polyline); } } } }
/// <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 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 UpStreamFindParcels(MainFrm pMainFrm, IEnumNetEID pEnumResultEdges, IGeometricNetwork pGeoNetwork) { try { AxMapControl axMap = pMainFrm.getMapControl(); IFeatureLayer pFeatLayerSewerLines = FindFeatLayer("Sewer Lines", pMainFrm); IFeatureLayer pFeatLayerParcels = FindFeatLayer("Parcels", pMainFrm); //从所选择的Sewer线特征中创建几何包 IGeometryCollection pGeomBag = new GeometryBagClass(); object missing = Type.Missing; int lEID; int iUserClassID; int iUserID; int iUserSubID; INetElements pNetElements = pGeoNetwork.Network as INetElements; pEnumResultEdges.Reset(); IFeature pFeature; for (int j = 0; j <= pEnumResultEdges.Count - 1; j++) { lEID = pEnumResultEdges.Next(); pNetElements.QueryIDs(lEID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID); pFeature = pFeatLayerSewerLines.FeatureClass.GetFeature(iUserID); pGeomBag.AddGeometry(pFeature.Shape, ref missing, ref missing); // MessageBox.Show(iUserClassID.ToString()+","+iUserID.ToString()+","+iUserSubID.ToString()); } //进行空间拓扑叠加操作以用于查找地块信息 ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = pGeomBag as IGeometry ; pSpatialFilter.GeometryField = "Shape"; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial; //获得交叉到的地块信息 IFeatureCursor pFeatCursor=pFeatLayerParcels.FeatureClass.Search(pSpatialFilter, false); //增加被选择的地块数据到地图的图形图层数据中 ICompositeGraphicsLayer pComGraphicLayer = new CompositeGraphicsLayerClass(); ILayer pLayer = pComGraphicLayer as ILayer ; pLayer.Name = "受影响的地块"; IGraphicsContainer pGraphicContainer = pComGraphicLayer as IGraphicsContainer; //增加所选择的地块到图形容器中 ISimpleFillSymbol pSymFill=new SimpleFillSymbolClass(); IFillSymbol pFillSymbol=pSymFill as IFillSymbol; IRgbColor pRgbColor=new RgbColorClass(); pRgbColor.Red=0; pRgbColor.Green=200; pRgbColor.Blue=100; pFillSymbol.Color=pRgbColor as IColor; ICartographicLineSymbol pCartoLine=new CartographicLineSymbolClass(); IRgbColor pRgbColor2=new RgbColorClass(); pRgbColor2.Red=100; pRgbColor2.Green=200; pRgbColor2.Blue=100; pCartoLine.Width=2; pCartoLine.Color =pRgbColor2 as IColor; pFillSymbol.Outline=pCartoLine; //创建存放所有地块特征的数组 IArray pFeatArray = new ArrayClass(); pFeature=pFeatCursor.NextFeature(); while (pFeature != null) { IElement pPolyElement = new PolygonElementClass(); IFillShapeElement pFillShapeElement = pPolyElement as IFillShapeElement; pPolyElement.Geometry = pFeature.Shape; pFillShapeElement.Symbol = pFillSymbol; pGraphicContainer.AddElement(pPolyElement, 0); pFeatArray.Add(pFeature); pFeature = pFeatCursor.NextFeature(); } axMap.AddLayer(pGraphicContainer as ILayer); axMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null); frmUpstreamCreateOwnerList frmUpstreamCreateOwnerList1 = new frmUpstreamCreateOwnerList(pMainFrm,pFeatLayerParcels, pFeatArray); frmUpstreamCreateOwnerList1.Show(); } catch (Exception eX) { MessageBox.Show(eX.Message); } }