Is there a way to query all pipes between two nodes - network analysis
hawklorry opened this issue · 1 comments
hawklorry commented
We have a list of upgrades (~400) list in a Excel file. Each upgrade has a from node and to node. We want to get select the pipes in between and get their size. Please let me know if it's possible to do this.
gedaskir commented
I hope I understood your request correctly, but I think this could be done with a script like this:
import mikeio1d
from mikeio1d.res1d import Res1D
def get_diameter(reach):
try:
grid_points = list(reach.GridPoints)
h_point = grid_points[0]
diameter = h_point.CrossSection.Diameter
except:
diameter = None
return diameter
def create_node_ids_to_reach_map(res1d):
reaches = list(res1d.data.Reaches)
nodes = list(res1d.data.Nodes)
node_ids_to_reach_map = dict()
for reach in reaches:
node_from_index = reach.StartNodeIndex
node_to_index = reach.EndNodeIndex
node_from = nodes[node_from_index]
node_to = nodes[node_to_index]
node_reach_label = (node_from.ID, node_to.ID)
node_ids_to_reach_map[node_reach_label] = reach
return node_ids_to_reach_map
def print_link_geometries(upgrades, node_ids_to_reach_map):
for upgrade in upgrades:
node_from_id, node_to_id = upgrade
reach = node_ids_to_reach_map[upgrade]
diameter = get_diameter(reach)
print("Link ID:", reach.Name)
print(" From Node ID:", node_from_id)
print(" To Node ID:", node_to_id)
print(" Diameter:", diameter)
print(" Length:", reach.Length)
filepath = "Network.res1d"
res1d = Res1D(filepath)
node_ids_to_reach_map = create_node_ids_to_reach_map(res1d)
# List of tuples with ids of from node and to node
upgrades = [('105', '38'), ('112', '101'), ('52', '51')]
print_link_geometries(upgrades, node_ids_to_reach_map)