Where subcatchments drains to?

In InfoWorks ICM you can extend model building functionalities with SQL and Ruby scripts. This blog is an example of how to define the nodes to which subcatchments drain using these tools. The scripts presented can be easily adapted to “drain to” links or subcatchments.

If you are modelling subcatchments that cover areas with one node only, you can use a simple SQL script. This is a common situation in urban drainage models, where subcatchments are usually delineated for each node. The SQL script simply sets the node to where the subcatchment drains to the node that it contains, as presented in the next figure.

Figure 1. SQL script to connect subcatchments with the overlay node.

You can also explore the “Nearest” function that was added to SQL scripts in InfoWorks ICM version 7.5.0. When using this function with polygons, it considers the nearest distance to the polygon boundary.

If your model contains subcatchments that cover areas with more than one node, the node where the subcatchments drain to can be considered to be the closest to the polygon centroid. This can be implemented easily in a ruby script with few lines as follows:


net=WSApplication.current_network
net.transaction_begin

puts ‘Connecting subcatchments to the closest node to centroid:’

subcatchment=net.row_objects(‘hw_subcatchment’).each do |subcatchment|
x=subcatchment.x
y=subcatchment.y
di=9999999999
dischargeNode=”
node=net.row_objects(‘hw_node’).each do |node|
tdi=((x-node.x)**2+(y-node.y)**2)**0.5
if (tdi<di)
dischargeNode=node[‘node_id’]
di=tdi
end
end
puts subcatchment[‘subcatchment_id’]+’:’+ dischargeNode
subcatchment[‘node_id’] = dischargeNode
subcatchment.write
end

net.transaction_commit

puts ‘Well done!’

You can run this script in InfoWorks ICM with the file attached this post. The file is a simple text file with the script and an extension “.rb”. To run it, you have to open a model network and click “Network > Run Ruby Script…” as shown in the next figure.

Figure 2. Running Ruby scripts in ICM.

It should be mentioned that the last option proposed is based on the closest distance to the centroid only. This may be acceptable in most of the situations, but can result in incorrect or unrealistic connections depending on the subcatchment shape and the nodes in the areas they cover. It is your responsibility to decide if you can apply this methodology.

This is an example of how flexible InfoWorks ICM is and of what you can do with SQL and Ruby scripts. The scripts presented defines the nodes where subcatchments drain and you can easily adapt them to drain for links or subcatchments.

Share this post!

    About Rui Daniel Pina

    Rui Daniel Pina is a Technical Support Engineer with Innovyze in the United Kingdom. Rui has experience in hydrology and hydraulic modelling, and is responsible for providing support of Infoworks ICM.
    This entry was posted in InfoWorks ICM and tagged , , . Bookmark the permalink.