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.
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:
puts ‘Connecting subcatchments to the closest node to centroid:’
subcatchment=net.row_objects(‘hw_subcatchment’).each do |subcatchment|
node=net.row_objects(‘hw_node’).each do |node|
puts subcatchment[‘subcatchment_id’]+’:’+ dischargeNode
subcatchment[‘node_id’] = dischargeNode
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.