# QGIS Finding valves to turn off for water lines

I am wondering if there is a tool for QGIS that can do what I am about to describe. It might be in network analysis but I am not sure. I have used water gems but it does not do what I want it to do.

Lets say I have a network of water lines. These water lines all have valves. Now, lets say I have to fix a certain spot on one line and I need to know all the valves that needs to be turned off to shut off the water to that line so the men can work on that line.

How can this be done?

What would be nice is that I am able to chose the line and point where the breakage is located and it tells me all the valves that need to be turn off to stop the water.

Any idea if there is a tool like that already or even how could we do this with Python?

• From my search, I think I might be able to use pgRoute to accomplish what I want. I am still researching. pgRoute finds the least cost path, which I can use a point to mark the pipe break and from that point maybe calculate all the least cost path to the valves and then highlight those values. Jan 18, 2016 at 22:59
• Steven Kay What is drive-time' algorithm ? Has your solution worked ? is there a sample code? Is there a database solution sql server? Apr 25, 2019 at 12:27

You could use NetworkX. This has the ability to create a network from a shapefile. Not tried it myself, though.

PgRouting is another possibility.

In the diagram below,

• the big red dot is the broken pipe.
• Pink circles are values we need to switch off.
• Grey circles are valves we don't need to switch off.
• Small black circles are where pipes join each other, without a valve.

You'll need to node your network...

• You'll need to add a node to the network where the break occurs.
• Where a valve falls within a pipeline, split the line by creating a node.

Next, assign weights to the edges, depending on what is at each end of the pipe segment:-

• intersection to intersection, weight = 0
• intersection to valve, weight = 1
• valve to valve, weight = 1

If you start at the broken pipe and use a 'drive-time' algorithm, the nodes which are reached with a `total cost of 1` are the valves you want to turn off.

• Hey sorry to be critical - but the above algorithm, as shown in your diagram, is actually flawed. The logic identifies the two valves that are in the southern looped part of the network are identified as needing to be shutoff. But in actual fact, if you shutoff the other 4 valves, the loop part will no longer have any source water, and thus, will not need to be turned off. Your logic needs to take into account source. (also you have a valve at a t-intersection, which generally doesn't happen. at least not a shutoff valve). Jul 18, 2022 at 7:18