Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

scrollbar

First of all, we will declare the folder where the shape and csv files are located. More data will be found in this same folder so we will be using this variable along the tutorial.

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

 

Then, we start creating the very basic network (made of branches and nodes). This information can be found in the GIS shape file network_Branches.shp. 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" library
from Libraries.SOBEKTutorialLibrary import *

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

At this point, it is important to make an observation. It is a good practice to place line of code to import libraries at the top of your script in a separate region. This will help you keep your code tidy and easier to 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 lines of code can be integrated analogously 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 corresponding to imports would then go to the first region Import libraries.

Let's now continue with the script. In this just imported 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 network will be created using the shape file and added to the variable "network" (if you to see how the network is created in more detail you can look at the CreateNetworkFromBranchShapeFile function in the SOBEKTutorialLibrary.py file in the libraries folder).

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"

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

And AddBridgesToNetwork for bridges

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

For the laterals and weirs we use the function :

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

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

 

Now that we have finished adding the structures to the network (for this tutorial), we can 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 and StandardFunctions for adding the model to the project )

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

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

AddToProject(flowModel)

 

Now we can see our model by opening a view for it using the "OpenModelMapViewWithBackground" call :

Code Block
languagepy
titleOpen map for model
OpenModelMapViewWithBackground(flowModel)

You should get something like this :

 

scrollbar