We will now add an observation point to the model. First, we create an instance of the point feature (Feature2DPoint), with the name "Observation point 1", located at an offset of 100000 from the lower left corner of the grid. This point is then added to the set containing all observation points (ObservationPoints, in the Area property of the fmModel).
Code Block |
---|
language | py |
---|
title | Add observation point |
---|
|
observationPoint = Feature2DPoint(Name = "Observation point 1", Geometry = mf.CreatePointGeometry(xOffset + 100000, yOffset + 100000))
fmModel.Area.ObservationPoints.Add(observationPoint) |
The observation point will now be placed more or less in the center of the grid.
![](/download/attachments/105874501/ObservationPoint.png?version=1&modificationDate=1413273596000&api=v2)
Then, we continue by adding the left and top boundaries to the model. Both boundaries are stored in variables for future reference.
Code Block |
---|
language | py |
---|
title | Add top and left boundary |
---|
|
leftBoundary = CreateBoundary("LeftBoundary", xOffset, yOffset, xOffset, yOffset + gridHeight, 6) # 6 support points
topBoundary = CreateBoundary("TopBoundary", xOffset, yOffset + gridHeight, xOffset + gridWidth, yOffset + gridHeight, 6) # 6 support points |
The function CreateBoundary generates a boundary which spans between the two points indicated by their respective coordinates. This boundary entity will contain the specified number of support points. The coordinates of the vertices of the boundaries are :
- bottomLeft: (xOffset, yOffset)
- topLeft: (xOffset, yOffset + gridHeight)
- topRight: (xOffset + gridWidth , yOffset + gridHeight)
Once the boundary objects have been created, we add them to the model using the variables earlier mentioned:
Code Block |
---|
language | py |
---|
title | Add boundaries |
---|
|
fmModel.Boundaries.AddRange([leftBoundary, topBoundary]) |
The boundaries will then be shown in the map:
![](/download/attachments/105874501/TopBoundary.png?version=1&modificationDate=1413275731000&api=v2)
Next, we must add boundaries to the bottom and right edges of the model. But this requires to know the maximum X value of the bottom row of the grid, and the minimum Y value of the column edge to the right of the girdgrid. In order to find these numbers, we create two new functions. The function GetMinMaxXFor searches along all the vertices with a Y coordinate equal to a specific value y, to find the minimum and maximum values of the X coordinate. The function GetMinMaxYFor is analogous, but in the other direction.
Code Block |
---|
language | py |
---|
title | Create min max functions for grid |
---|
|
def GetMinMaxXFor(vertices, y):
minvalue = None
maxvalue = None
for vertex in vertices:
if (vertex.Y == y):
if (maxvalue == None or vertex.X > maxvalue):
maxvalue = vertex.X
if (minvalue == None or vertex.X < minvalue):
minvalue = vertex.X
return minvalue, maxvalue
def GetMinMaxYFor(vertices, x):
minvalue = None
maxvalue = None
for vertex in vertices:
if (vertex.X == x):
if (maxvalue == None or vertex.Y > maxvalue):
maxvalue = vertex.Y
if (minvalue == None or vertex.Y < minvalue):
minvalue = vertex.Y
return minvalue, maxvalue |
Using these functions, we can find the above indicated missing coordinates of the extremes of the boundaries, which are then created and stored in variables for later use.
Code Block |
---|
language | py |
---|
title | Add bottom and right boundary |
---|
|
minMaxX = GetMinMaxXFor(fmModel.Grid.Vertices, yOffset)
bottomBoundary = CreateBoundary("BottomBoundary", xOffset, yOffset, minMaxX[1], yOffset, 3) # 3 support points
minMaxY = GetMinMaxYFor(fmModel.Grid.Vertices, xOffset + gridWidth)
rightBoundary = CreateBoundary("RightBoundary", xOffset + gridWidth, yOffset + gridHeight, xOffset + gridWidth, minMaxY[0], 3) # 3 support points
|
Once they have been created, they are added to the model using the just assigned variables:
Code Block |
---|
language | py |
---|
title | Add boundaries |
---|
|
fmModel.Boundaries.AddRange([bottomBoundary, rightBoundary]) |
All boundaries will now be shown in the map of the model.
![](/download/attachments/105874501/Boundaries.png?version=1&modificationDate=1414068771000&api=v2)
To keep your script clean, you can move the functions to your own library. The steps to do this are:
- Create a new script in the toolbox.
- Add the functions created above to this new script.
- Save the new script.
- Go back to the main script.
- Add an import statement to this library (e.g. from NewLib Import *). This can be quickly done if you use the toolbox panel:
- Place the cursor in the position of the main script where you want the import statement to be added.
- Select the new script in the toolbox panel.
- Right click on it.
- Select the option Add as import. The code of line to import the library will be automatically added to the main script.
The boundaries just added are initially empty. They will be specified in the next step of this tutorial.