Problem with pTraceFlowSolver.FindFlowElements

4044
15
Jump to solution
02-11-2011 05:14 PM
kromopawiro
New Contributor
Dear All,

I have coding snippet for tracing a network,Below this coding snippet :

Public Sub TraceNetworks(ByVal pMap As IMap, ByVal pFlowMethod As ESRI.ArcGIS.NetworkAnalysis.esriFlowMethod, ByVal pFeature As IFeature, ByRef pIEnumJunctionEIDInfo As ESRI.ArcGIS.NetworkAnalysis.IEnumEIDInfo, ByRef pIEnumEdgeEIDInfo As ESRI.ArcGIS.NetworkAnalysis.IEnumEIDInfo)
Dim pNetworkFeature As INetworkFeature
Dim pGeometricNetwork As IGeometricNetwork
Dim pTraceFlowSolver As ESRI.ArcGIS.NetworkAnalysis.ITraceFlowSolver
Dim pNetSolver As ESRI.ArcGIS.NetworkAnalysis.INetSolver
???Dim pNetwork As ESRI.ArcGIS.Geodatabase.INetwork
Dim pFeatureClass As IFeatureClass
Dim pJunctionEIDs As ESRI.ArcGIS.Geodatabase.IEnumNetEID = Nothing
Dim pEdgeEIDs As ESRI.ArcGIS.Geodatabase.IEnumNetEID = Nothing

pNetworkFeature = pFeature
pGeometricNetwork = pNetworkFeature.GeometricNetwork

pTraceFlowSolver = New ESRI.ArcGIS.NetworkAnalysis.TraceFlowSolver

pFeatureClass = pFeature.Table

???Create junction flag from selected feature
If pFeature.FeatureType = ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTComp lexEdge Or pFeature.FeatureType = ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimp leEdge Then
Dim pEdgeFlag As ESRI.ArcGIS.NetworkAnalysis.INetFlag
pEdgeFlag = New ESRI.ArcGIS.NetworkAnalysis.EdgeFlag
pEdgeFlag.UserClassID = pFeatureClass.FeatureClassID
pEdgeFlag.UserID = pFeature.OID
pEdgeFlag.UserSubID = -1
Dim pEdgeFlags(0) As ESRI.ArcGIS.NetworkAnalysis.IEdgeFlag
???Add the flag to the array
pEdgeFlags(0) = pEdgeFlag
pTraceFlowSolver.PutEdgeOrigins(1, pEdgeFlags(0))
ElseIf pFeature.FeatureType = ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimp leJunction Then
Dim pJunctionFlag As ESRI.ArcGIS.NetworkAnalysis.INetFlag
pJunctionFlag = New ESRI.ArcGIS.NetworkAnalysis.JunctionFlag
pJunctionFlag.UserClassID = pFeatureClass.FeatureClassID
pJunctionFlag.UserID = pFeature.OID
pJunctionFlag.UserSubID = 0
Dim pJunctionFlags(0) As ESRI.ArcGIS.NetworkAnalysis.IJunctionFlag
pJunctionFlags(0) = pJunctionFlag
pTraceFlowSolver.PutJunctionOrigins(1, pJunctionFlags(0))
Else
Exit Sub
End If

pTraceFlowSolver.TraceIndeterminateFlow = False

pTraceFlowSolver.FindFlowElements(pFlowMethod, ESRI.ArcGIS.NetworkAnalysis.esriFlowElements.esriF EJunctionsAndEdges, pJunctionEIDs, pEdgeEIDs)

Dim pEIDHelper As ESRI.ArcGIS.NetworkAnalysis.IEIDHelper
pEIDHelper = New ESRI.ArcGIS.NetworkAnalysis.EIDHelper
pEIDHelper.ReturnFeatures = True
pEIDHelper.GeometricNetwork = pGeometricNetwork
pEIDHelper.OutputSpatialReference = pMap.SpatialReference

pIEnumJunctionEIDInfo = pEIDHelper.CreateEnumEIDInfo(pJunctionEIDs)
pIEnumEdgeEIDInfo = pEIDHelper.CreateEnumEIDInfo(pEdgeEIDs)

Dim i As Integer

Dim pEIDInfo As ESRI.ArcGIS.NetworkAnalysis.IEIDInfo
Dim pDataset As IDataset
If pFlowMethod ESRI.ArcGIS.NetworkAnalysis.esriFlowMethod.esriFMC onnected Then
???m_pClearSelectCommand.OnClick()
???SetSelectionSymbol(True, pFlowMethod)
End If

For i = 1 To pIEnumJunctionEIDInfo.Count
pEIDInfo = pIEnumJunctionEIDInfo.Next
pFeature = pEIDInfo.Feature
pDataset = pFeature.Table

If pFlowMethod ESRI.ArcGIS.NetworkAnalysis.esriFlowMethod.esriFMC onnected Then
If Trim(UCase(Split(pDataset.Name, ???.???)(1))) ???ASET_NET_JUNCTIONS??? Then
pMap.SelectFeature(GetLayerByName(pDataset.Name), pFeature)

End If
End If
Next i

For i = 1 To pIEnumEdgeEIDInfo.Count
pEIDInfo = pIEnumEdgeEIDInfo.Next
pFeature = pEIDInfo.Feature
pDataset = pFeature.Table
If pFlowMethod ESRI.ArcGIS.NetworkAnalysis.esriFlowMethod.esriFMC onnected Then
pMap.SelectFeature(GetLayerByName(pDataset.Name), pFeature)

End If
Next i

Map1.Refresh()
End Sub

I have error in statement ???pTraceFlowSolver.FindFlowElements(pFlowMethod, ESRI.ArcGIS.NetworkAnalysis.esriFlowElements.esriF EJunctionsAndEdges, pJunctionEIDs, pEdgeEIDs)???.

Message Error :

???Error HRESULT E_FAIL has been returned from a call to a COM component.???

I hope you can help me solution about problem above . Thank???s before

Regard

-Doni-
0 Kudos
1 Solution

Accepted Solutions
nicogis
MVP Frequent Contributor

Inizialized Flow Direction if you need downstream or upstream

you can use similiar code for find edge in downstream or upstream with your business logic.


 INetTopologyEditGEN netTopology = networkElements as INetTopologyEditGEN;


                            int edgeCount = netTopology.GetAdjacentEdgeCount(yourEIDJunction);








                            bool reverseOrientation;
                            int adjacentEdge;
                            for (int i = 0; i < edgeCount; i++)
                            {
                                netTopology.GetAdjacentEdge(yourEIDJunction, i, out adjacentEdge, out reverseOrientation);
                              


                                netTopology.GetFromToJunctionEIDs(adjacentEdge, out fromEIDJunction, out toEIDJunction);


reverseOrientation = true // into Junction   -> upstream

reverseOrientation = false // exit Junction   -> downstream

View solution in original post

15 Replies
jyotsnasali1
New Contributor
hi there

I am new to AO.It would be great if u share complete tracing code with me

tks
0 Kudos
MilosMilicevic
New Contributor

Hello,

I have been trying to do the same, and I keep getting the same error.

Did You find a solution to this?

Thanks.

0 Kudos
ShriramBhutada1
New Contributor III

Hi Kromo,

I can see that network is not set for the ITraceFlowSolver. you can doing this by following code. Cast the ITraceFlowSolve to a INetSolver and set the sourceNetwork with INetwork which can get access from IGeometricNetwork::Network. May be this will help.

Dim pNetSolver As ESRI.ArcGIS.NetworkAnalysis.INetSolver
Set pNetSolver = ipTraceFlowSolver

Set ipNetwork = pGeometricNetwork.Network
Set pNetSolver.SourceNetwork = ipNetwork

0 Kudos
ShriramBhutada1
New Contributor III

Here is the documentation on that..

ArcObjects 10 .NET SDK Help

"Use the INetSolver interface to specify which network on which you want to perform an analysis, which elements in the network are barriers, and which element classes are disabled."

"When you create a TraceFlowSolver object, you also get a reference to a NetSolver object, since TraceFlowSolver inhereits from NetSolver."

0 Kudos
MilosMilicevic
New Contributor

This helped me:

https://community.esri.com/message/15434?sr=search&searchId=a454f382-ad3d-4d79-8a35-b837bf8ed7b8&sea...

Now I am trying to get feature class of e.g. junction that was returned to me by the trace.

I got this far:

pTraceFlowSolver.FindFlowElements(strTraceType,esriFlowElements.esriFEJunctionsAndEdges, out pJunctionEIDs, out pEdgeEIDs);

           int idJunction = pJunctionEIDs.Next();

           while (idJunction != -1)

           {

              

               idJunction = pJunctionEIDs.Next();

              

           }

How can I get a layer, or feature class or something that can give me attributes of the returned objects.

All I have is ID of a junction.

Tnx,

0 Kudos
ShriramBhutada1
New Contributor III

Hi Milos,

One can get featureclass id from EID with INetworkElements.QueryIDs interface

ArcObjects 10 .NET SDK Help

Here is some quick sample code

Dim userclassid1 As Long, userid1 As Long, usersubid1 As Long
Dim pNetElements As INetElements
Set pNetElements = pNetwork
pNetElements.QueryIDs EIDp, esriETEdge, userclassid1, userid1, usersubid1

Debug.Print "classid: " & userclassid1 & " userid: " & userid1 & " subid: " & usersubid1

0 Kudos
ShriramBhutada1
New Contributor III

btw pNetwork is INetwork in the above code.

Dim pNetwork As INetwork

Set pNetwork = pGeometricNetwork.Network

0 Kudos
MilosMilicevic
New Contributor

Hello Shriram ,

Thnks for helping out.

This works, but I keep getting the Feature for which I did the trace (e.g. I did an upstream trace and in junctions I get ID of the feature which is a consumer, not the ID of a feature that is a source)...

Any ideas what I did wrong?

I copied the code from the link above, and just changed some minor stuff....

Tnx.

0 Kudos
ShriramBhutada1
New Contributor III

Hi Milo,

No sure of the exact problem - seems like a workflow issue. I think that is worth re-looking is. ITraceFlowSolver.PutJunctionOrigins. The documentation says use ITraceFlowSolverGEN::PutJunctionOrigins. from VB.NET.

"

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

[C#]

This method is not callable from C#.  Please use ITraceFlowSolverGEN::PutJunctionOrigins.

[Visual Basic .NET]

This method is not callable from VB.NET.  Please use ITraceFlowSolverGEN::PutJunctionOrigins.

"

ArcObjects 10 .NET SDK Help

0 Kudos