Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
HTML
<script type="text/javascript">
    
 AJS.toInit(function() {
 // unbind directly-embedded images
 AJS.$("img.confluence-embedded-image").unbind("click.fb");
 });
 </script>

scrollbar

First of all, we will declare the folder The fist thing we have to do is declare where the shape and csv files are located :. More data will be found in this same folder, so this variable will be used multiple times along the tutorial.

Code Block
languagepy
titleDeclare paths
rootPath = r"D:\Workshop\data"

We now start

by

creating the very basic network (

consisting

made of branches and nodes)

using the "

. This information can be found in the GIS shape file network_Branches.shp

" shape file.

 

 

For this we will need to use a library called "SOBEKTutorialLibrary" in the "Libraries" folder of the toolbox. This is done by adding the following line (and running it). The required importer can be found in the library called SOBEKTutorialLibrary in the Libraries folder of the toolbox. You can gain access to all the methods included in that library by adding (and then running) the following code.

Code Block
languagepy
titleImport "SOBEKTutorialLibrary" libraryall functionality from a library file
from Libraries.SOBEKTutorialLibrary import *

This will The mask * (asterisk) written after the keyword import will load and make all the functions (because of the *) contained in the "SOBEKTutorialLibrary" library  library available for use. All these functions of them will now also appear in the code completion dialog (when you use ctrl + space).when you hit CTRL + SPACE.

At this point, it is important to make an observation. It is a good practice to place the lines of code used to import libraries at the top of your script, in a separate region. This will help you keep your code tidy and easier to understand, update and maintain. Therefore, place the line above completely at the top of your script, select it and then create a region for it (pressing CTRL+R). You can call it Import libraries.
The other line of code can be analogously integrated is a different region (for example one called Create network). The rest of the main code in this section can also be placed in this same region Create network. The code that you type in the future corresponding to imports would then go to the first region Import libraries. And the specific for each section to its respective region.

Let's now continue with the script. In this just imported In this library we have a function called "CreateNetworkFromBranchShapeFile"   Image Added  which we will use to create the basic network.

Code Block
languagepy
titleCreate basic network
network = CreateNetworkFromBranchShapeFile(rootPath + r"\network_Branches.shp")
After running this line the  model is imported and added to the variable "hydroModel", but we can not see the model yet

When you run this line of the script, the network will be created using the indicated shape file and assigned to the variable network.

Now that we have a network with branches and nodes, we can continue with the import of the cross-sections. This is done with the function AddCrossSectionsToNetwork   Image Added . The shape file contains the location of the different cross sections as well as some generic properties. The tables specifying the cross section profiles are stored in the csv file.

Code Block
languagepy
titleAdd cross-sections to network
AddCrossSectionsToNetwork(rootPath + r"\network_Cross Sections.shp", rootPath + r"\CrossSectionProfiles.csv", network)

Anagolously, for the bridges we use the function AddBridgesToNetwork Image Added . As in the previous case, the shape file contains the location of the different bridges, as well as some other generic properties. The tables specifying the cross sections at the bridges are stored in the csv file.

Code Block
languagepy
titleAdd bridges to network
AddBridgesToNetwork(rootPath + r"\network_Bridges.shp", rootPath + r"\BridgeProfiles.csv", network)

We will import the lateral sources and the weirs with one single function AddBranchObjectsFromShapeFile Image Added . In this case, there is no table associated (this is an assumption we make for the sake of simplicity). Therefore, no associated csv file will need to be imported.

Code Block
languagepy
titleAdd lateral sources and weirs to network
from Libraries.NetworkFunctions import BranchObjectType # Import libraries region

AddBranchObjectsFromShapeFile(BranchObjectType.LateralSource, rootPath + r"\network_Lateral Sources.shp", network)
AddBranchObjectsFromShapeFile(BranchObjectType.Weir , rootPath + r"\network_Weirs.shp", network)

 

The network is complete now that we have finished adding the structures to it. We can next create a new waterflow model and add this network to it.

First, we need to import two more libraries: SobekWaterFlowFunctions to be able to create a WaterFlowModel1D Image Added and StandardFunctions for adding the model to the project with the AddToProject  Image Added function.

Code Block
languagepy
titleCreate waterflow model and add network
from Libraries.SobekWaterFlowFunctions import *  # Import libraries region
from Libraries.StandardFunctions import *  # Import libraries region

flowModel = WaterFlowModel1D()
flowModel.Network = network
flowModel.Name = "Flow model"

AddToProject(flowModel)

 

Now, we will be able to see the model we have created so far by opening the corresponding view for it using the OpenModelMapViewWithBackground Image Addedmethod.

Code Block
languagepy
titleOpen map for model
OpenModelMapViewWithBackground(flowModel)

You should get something like this :

Image Added

 

Note: The icon Image Added indicates functions that you might find interesting to see how they have been built. You can do this by opening the corresponding library (another normal script python file on its own) in the toolbox and checking the code which defines the function or method you are interested in.

scrollbar