Exercise outline
We want to create a station class (data structure) that can hold the data of one station. Then we make a list containing all the stations in the NetCdf file and fill it with the data of the NetCdf file.
Add monitoring points for stations in envelope
Add the following import statements to the region Import libs:
# DeltaShell libs from DelftTools.Hydro2D.Features import Feature2DPoint from DeltaShell.Plugins.FMSuite.FlowFM.Layers import UnstructuredGridLayer
And add this code to the end of the script :
#region Add monitoring points for stations in envelope # Get bounding box of grid gridLayer = UnstructuredGridLayer() gridLayer.Grid = fmModel.Grid envelope = gridLayer.Envelope # Get stations in envelope stationsInEvelope = [] for station in stationList: if (gridLayer.Envelope.Contains(station.geometry.Coordinate)): stationsInEvelope.append(station) print "Nr of stations in grid extend : " + str(len(stationsInEvelope)) # Add monitoring point at station locations for station in stationsInEvelope: observationPoint = Feature2DPoint() observationPoint.Name = station.name observationPoint.Geometry = station.geometry fmModel.Area.ObservationPoints.Add(observationPoint) print "Added : " + station.name + " to observation points" #endregion
we start by getting the bounds of the grid. We do this by creating a grid layer (UnstructuredGridLayer) and get the Envelope property:
# Get bounding box of grid gridLayer = UnstructuredGridLayer() gridLayer.Grid = fmModel.Grid envelope = gridLayer.Envelope
Now we create a new list for the stations that are in the grid envelope, and loop through all the stations to see if they are in the envelope:
# Get stations in envelope stationsInEvelope = [] for station in stationList: if (gridLayer.Envelope.Contains(station.geometry.Coordinate)): stationsInEvelope.append(station) print "Nr of stations in grid extend : " + str(len(stationsInEvelope))
We can now use these stations to create observation points (Feature2DPoint) using the name and geometry of the stations
# Add monitoring point at station locations for station in stationsInEvelope: observationPoint = Feature2DPoint() observationPoint.Name = station.name observationPoint.Geometry = station.geometry fmModel.Area.ObservationPoints.Add(observationPoint) print "Added : " + station.name + " to observation points"