I'm developing an ArcMap add-in that will run a trace against a water main that the user has selected using the selection tool. The geometric network is already defined and I can run the trace by manually placing the edge barriers at each end of the main, putting an edge flag somewhere on the water main between the edge barriers and then tracing downstream (using indeterminate flow). This returns all the curbstop valves that are connected to the water main.

I'd like to automate this so that the user doesn't need to place barriers or flag(s) but just needs to select the water main and hit a button to preform the trace. I guess my pseudocode would be something like:

  1. User selects a water main
  2. User clicks my Add-In button
  3. Programmatically place Edge Barrier at both ends of selected water main segment
  4. Programmatically place Flag somewhere between barriers to indicate where to start trace from
  5. Run the trace

Is what I want to do even possible? How can I add flags and barriers to a selected segment of a geometric network using ArcObjects?

2 Answers 2


Late but here is a suggestion. You can call Trace Geometric Network geoprocessing tool from ArcObjects and you can pass any IFeatureLayer in it as flags or barriers.

You should be able to create a point on selected water main using ICurve.QueryPoint and save this point to IFeatureLayer and use it as a flag. If you have some layer in your network which represents ends of water segments than you can use this layer as barriers (just cast ILayer to IFeatureLayer).

  • Thanks for the idea (and reminding me that I had to post my answer!) Commented Jun 10, 2015 at 15:33

Ok, so what I wound up doing was very similar to my pseudo code in my question. I was able to programatically create Points at the ends an middle of the selected water main feature... Then use those points to programmatically add the barriers and start flag to the geometric network. The revised pseudo-code of my solution is:

  1. User selects water mains
  2. User clicks Add-In button
  3. Create a PolyLine object by calling

    watermainPolyLine = selectedWaterMainFeature.ShapeCopy

  4. Create two Points (a point for each end/barrier) by calling

    watermainPolyLine.QueryPoint(..., 0.0, ..., endPoint1 ) 


    watermainPolyLine.QueryPoint(..., 1.0, ..., endPoint2)
  5. Create a point (for the middle/start flag) by calling

    watermainPolyLine.QueryPoint(..., 0.5, ..., endPoint2)
  6. Add barriers and start flag to the Geometric Networm using the points created in 4. and 5.
  7. Set up a NetworkSolver object and TraceFlowSolver object and perform the trace.

This works quite well. I expanded the solution to allow the user to have multiple water main segments selected. A caveat to this approach was that the Solver objects seemed to get confused when tracing against multiple start flag and barrier combinations (the solver objects became inconsistent... sometimes they would work properly, sometimes they would crash, sometimes they would miss results). I remedied this problem by iterating through the selected water mains and performing the steps above.

  • If this is your answer then mark it an answer please Commented Jul 26, 2015 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.