104Public Property Get StopPoints() As esriGeometry.IPointCollection
105 Set StopPoints = m_ipPoints
106End Property
107
108' Calculate the path
109
110Public Sub SolvePath(WeightName As String)
111
112 Dim ipNetwork As esriGeoDatabase.INetwork
113 Dim ipTraceFlowSolver As esriNetworkAnalysis.ITraceFlowSolver
114 Dim ipNetSolver As esriNetworkAnalysis.INetSolver
115 Dim ipNetFlag As esriNetworkAnalysis.INetFlag
116 Dim ipaNetFlag() As esriNetworkAnalysis.IEdgeFlag
117 Dim ipEdgePoint As esriGeometry.IPoint
118 Dim ipNetElements As esriGeoDatabase.INetElements
119 Dim intEdgeUserClassID As Long
120 Dim intEdgeUserID As Long
121 Dim intEdgeUserSubID As Long
122 Dim intEdgeID As Long
123 Dim ipFoundEdgePoint As esriGeometry.IPoint
124 Dim dblEdgePercent As Double
125 Dim ipNetWeight As esriGeoDatabase.INetWeight
126 Dim ipNetSolverWeights As esriNetworkAnalysis.INetSolverWeights
127 Dim ipNetSchema As esriGeoDatabase.INetSchema
128 Dim intCount As Long
129 Dim i As Long
130 Dim vaRes() As Variant
131
132 ' make sure we are ready
133 Debug.Assert Not m_ipPoints Is Nothing
134 Debug.Assert Not m_ipGeometricNetwork Is Nothing
135
136 ' instantiate a trace flow solver
137 Set ipTraceFlowSolver = New esriNetworkAnalysis.TraceFlowSolver
138
139 ' get the INetSolver interface
140 Set ipNetSolver = ipTraceFlowSolver
141
142 ' set the source network to solve on
143 Set ipNetwork = m_ipGeometricNetwork.Network
144 Set ipNetSolver.SourceNetwork = ipNetwork
145
146 ' make edge flags from the points
147
148 ' the INetElements interface is needed to get UserID, UserClassID,
149 ' and UserSubID from an element id
150 Set ipNetElements = ipNetwork
151
152 ' get the count
153 intCount = m_ipPoints.PointCount
154 Debug.Assert intCount > 1
155
156 ' dimension our IEdgeFlag array
157 ReDim ipaNetFlag(intCount)
158
159 For i = 0 To intCount - 1
160 ' make a new Edge Flag
161 Set ipNetFlag = New esriNetworkAnalysis.EdgeFlag
162 Set ipEdgePoint = m_ipPoints.Point(i)
163 ' look up the EID for the current point (this will populate intEdgeID and dblEdgePercent)
164 m_ipPointToEID.GetNearestEdge ipEdgePoint, intEdgeID, ipFoundEdgePoint, dblEdgePercent
165 Debug.Assert intEdgeID > 0 ' else Point (eid) not found
166 ipNetElements.QueryIDs intEdgeID, esriETEdge, intEdgeUserClassID, intEdgeUserID, intEdgeUserSubID
167 Debug.Assert (intEdgeUserClassID > 0) And (intEdgeUserID > 0) ' else Point not found
168 ipNetFlag.UserClassID = intEdgeUserClassID
169 ipNetFlag.UserID = intEdgeUserID
170 ipNetFlag.UserSubID = intEdgeUserSubID
171 Set ipaNetFlag(i) = ipNetFlag
172 Next
173
174 ' add these edge flags
175 ipTraceFlowSolver.PutEdgeOrigins intCount, ipaNetFlag(0)
176
177 ' set the weight (cost field) to solve on
178
179 ' get the INetSchema interface
180 Set ipNetSchema = ipNetwork
181 Set ipNetWeight = ipNetSchema.WeightByName(WeightName)
182 Debug.Assert Not ipNetWeight Is Nothing
183
184 ' set the weight (use the same for both directions)
185 Set ipNetSolverWeights = ipTraceFlowSolver
186 Set ipNetSolverWeights.FromToEdgeWeight = ipNetWeight
187 Set ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight
188
189 ' initialize array for results to number of segments in result
190 ReDim vaRes(intCount - 1)
191
192 ' solve it
193 ipTraceFlowSolver.FindPath esriFMConnected, esriSPObjFnMinSum, m_ipEnumNetEID_Junctions, m_ipEnumNetEID_Edges, intCount - 1, vaRes(0)
194
195 ' compute total cost
196 m_dblPathCost = 0
197 For i = LBound(vaRes) To UBound(vaRes)
198 m_dblPathCost = m_dblPathCost + vaRes(i)
199 Next
200
201 ' clear the last polyline result
202 Set m_ipPolyline = Nothing
203
204End Sub
205
206' Property to get the cost
207
208Public Property Get PathCost() As Double
209 PathCost = m_dblPathCost
210End Property
211
责任编辑:小草