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).

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.

Then, we continue by adding the left and top boundaries to the model. Both boundaries are stored in variables for future reference.

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:

Add boundaries
fmModel.Boundaries.AddRange([leftBoundary, topBoundary])

The boundaries will then be shown in the map:

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 grid. 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.

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.

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:

Add boundaries
fmModel.Boundaries.AddRange([bottomBoundary, rightBoundary])

All boundaries will now be shown in the map of the model.

To keep your script clean, you can move the functions to your own library. The steps to do this are:

  1. Create a new script in the toolbox.
  2. Add the functions created above to this new script.
  3. Save the new script.
  4. Go back to the main script.
  5. Add an import statement to this library (e.g. from NewLib Import *). This can be quickly done if you use the toolbox panel:
    1. Place the cursor in the position of the main script where you want the import statement to be added.
    2. Select the new script in the toolbox panel.
    3. Right click on it.
    4. 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.

 

  • No labels