Select to view content in your preferred language

Problem with pTraceFlowSolver.FindFlowElements

5101
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
15 Replies
ShriramBhutada1
Deactivated User

Here is a code sample with documentation

ArcObjects 10 .NET SDK Help

0 Kudos
MilosMilicevic
Deactivated User

Hello Shriram,

I am already using  it:

ITraceFlowSolverGEN pTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;

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

It seems like it always returns the result of a Connected trace, no matter which trace method I specify.

I have a test network that consists of a source (a reservoir), a sink (water meter) water hydrant and two pipes.

Every time i get all the junctions returned, but only when I set the flag

pTraceFlowSolver.TraceIndeterminateFlow = true;

Otherwise, I only get the trace starting junction.

Could this be a matter of weights?

I am using default net solver weights...

Do You have a working example of net solver weights usage?

Tnx in advance.

0 Kudos
MilosMilicevic
Deactivated User

So I think I know what the issue is:

My network does not have Flow Direction initialized.

I suppose that this is why up/downstream traces do not work.

Actually, I do not need this, because my app is supposed to return nearest upstream and nearest downstream node of a selected node.

All my features have a weight field, which is initialized to 32768 for sources and 65536 for sinks.

Any idea how can I determine if a neighbour node is upstream or downstream?

It occured to me to use FindConnected trace and then find all the sinks, and sources, and determine the nearest ones.

But I cannot figure out if the node is up or downstream

0 Kudos
nicogis
MVP Alum

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

MilosMilicevic
Deactivated User

Hello Domenico,

Works great, thanks.

Thanks a lot.

Just one question:

Does this relay on the NetworkAncilarryRole Field (determines flow according to the Source/Sink value of the junction) ?

Because if it relies on that, it will not work for me.

I need nearest adjacent junctions on the up and downstream side, but according to NetWeight field.

Could I use IForwardStarGEN interface:

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IForwardStarGEN_Interfac...

It seems to have methods that take notice of weights...

Tnx again.

0 Kudos
nicogis
MVP Alum

Yes, it 's similar INetTopologyEditGen  but with IForwardStarGEN you have also the weight!

0 Kudos