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 | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
from Libraries.SOBEKTutorialLibrary import * |
The mask * (asterisk) written after the keyword import will load 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 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 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 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 library we have a function called CreateNetworkFromBranchShapeFile which we will use to create the basic network.
Code Block | ||||
---|---|---|---|---|
| ||||
network = CreateNetworkFromBranchShapeFile(rootPath + r"\network_Branches.shp") |
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 . 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 | ||||
---|---|---|---|---|
| ||||
AddCrossSectionsToNetwork(rootPath + r"\network_Cross Sections.shp", rootPath + r"\CrossSectionProfiles.csv", network) |
Anagolously, for the bridges we use the function AddBridgesToNetwork . As in the previous case, the shape file contains the location of the different bridgesas well as some generic properties. The tables specifying the cross sections at the bridges are stored in the csv file.
Code Block | ||||
---|---|---|---|---|
| ||||
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 . 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 | ||||
---|---|---|---|---|
| ||||
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 and StandardFunctions for adding the model to the project with the AddToProject function. )
Code Block | ||||
---|---|---|---|---|
| ||||
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 method.
Code Block | ||||
---|---|---|---|---|
| ||||
OpenModelMapViewWithBackground(flowModel) |
You should get something like this :
Note: The icon 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 |
---|
...