Pragmatic Geographer


Programmatically Tracing a Network in ArcGIS

Recently I was tasked with tracing a water network, and after studying a previous programmer’s work on the subject, I realized the solution is just a modified tree algorithm that is largely language independent.

The trick is a recursive function that continues to call itself until it has gone down the totality of a single path. When it can’t keep going – because it reaches the end of the line or because you convince the program it is the end of the line – it hops back one function call and tries to take an unvisited path. If it finds one, it repeats the whole process.

The ArcObjects API contains the extensions for Network and Utility Network tools, but as far as I can tell, those are mostly for listening for trace events rather than starting your own. Since a network like that is just a modified topology (it inherits from ESRI’s topology object), you can use ITopology to create a TopologyGraph which allows access to the Edges and Nodes required.

But you don’t need to use C#/VB.NET/VBA to pull this off. It would be possible with the API ESRI provides with its Python scripting object (IDispatch), as that contains start and end points in its Geometry object, or by creating your own node/tree structure.