Introduction

This How-to explains one way to define the grid for unstructured SWAN (unSWAN) / WW3 grids. The steps below describe how to produce the GridDefinitionShapefile.shp as shown in the Grids.xml excerpt below. The shapefile represents the faces of the grid cells as polygons: 

Grids.xml
	<irregular locationId="GridId">
		<esriShapeFile>
			<file>GridDefinitionShapefile.shp</file>
		</esriShapeFile>
	</irregular>

High-level steps

What you need:

  • Coordinates of the centerpoints of each cell in your irregular grid, in the same order as they will appear in the model data.
  • A shapefile representing the (land) boundary of your model. This is preferably the same boundary used to generate the grid in the first place.

You can follow these general steps using your tools of choice:

  1. Make a text file with each row representing the centerpoint of each cell in your irregular grid. The columns should include an ID, x-coordinate, and y-coordinate. The ID should be a unique, ascending number, which can later be used to sort the points back into their original order (should the order have been changed by GIS processing).
  2. Use a GIS application to load the point data.
  3. Convert the point data to Thiessen/Voronoi polygons.
  4. Convert your boundary shapefile to a polygon, if it isn't already a polygon
  5. Clip the Thiessen/Voronoi polygons using the boundary polygon
  6. If needed, sort the polygons such that they are in the same order as the original points, using the ID attribute mentioned in step 1.
  7. Inspect the polygon shapefile and confirm it has exactly the same number of elements as the original list of points. Overlay the points on the polygons - each polygon should have a point neatly in the middle.
  8. Save this shapefile in your MapLayerFiles and refer to it from Grids.xml (see above). If your shapefile is not in WGS84, you may need to add a <geoDatum> to the configuration.

Detailed steps, as developed for unSWAN

What you need:

  • .node file from your unSWAN model grid definition
  • .ldb land boundary file used to great that model grid (ask the modeller for this)

These more detailed steps use QGIS and Delft3D QUICKPLOT:

Tip: The following steps go much faster if the files are saved locally.

  1. Convert the .node file to a .csv
    1. Open the .node file in Excel (space delimited/treat consecutive delimiters as one).
    2. Scroll to row #999 - you likely need to shift the columns from there and onwards to the left to make sure they line up.
    3. Delete the first (empty) column.
    4. Replace the first line with some logical headers (e.g. ID, X, Y, Z, UNKNOWN)
    5. The first column should be a unique ID starting at 1 and going up - we use this to sort the table later if needed.
    6. Save the file as a CSV


  2. Load CSV in QGIS and save/export as point shapefile:
    1. Open QGIS
    2. Click on the ‘Open Data Source Manager’ icon.
    3. Select ‘Delimited Text’ at the top of the window.
    4. Click ‘Browse’ and locate the CSV file on your computer, then click ‘Open’.
    5. Ensure ‘CSV’ is selected as the file format.
    6. In "Geometry Definition" select the correct CRS (probably EPSG:4326 - WGS 84)
    7. Click Add, Close
    8. Right click the newly added layer --> Export --> Save Features As... --> ESRI Shapefile --> Specify a name and double check the CRS --> OK


  3. Run the QGIS Thiessen Polygon tool to make a polygon shapefile with Thiessen/Voronoi polygons
    1. Vector / Geometry Tools / Voronoi Polygons

  4. Convert the .ldb land boundary file to a polyline shapefile:
    1. Start Delft3D
    2. Click Utilities
    3. Click QUICKPLOT
    4. Open .ldb file
    5. Under Export File Type, select save as ARCview shape
  5. Convert the .ldb polyline shapefile to a polygon shapefile:
    1. Add the .ldb polyline shapefile to QGIS
    2. Define the Projection of the line shapefile as WGS 1984 (if that's correct) --> Right click --> Layer CRS --> Set Layer CRS --> Select (probably WGS 84) and click OK
    3. The polyline has to be a closed polyline before you can convert it to polygon - this should have been provided by the model developer
    4. Vector / Geometry Tools / Lines to Polygons (save to new shapefile)
    5. Run Vector / Geoprocessing Tools / Union to make sure water polygon includes island cutouts. [This and the following step is not needed if using ArcGIS]
    6. Do some manual selection to select the polygon(s) covering water areas (exclude land areas). e.g. by selecting the main water area, reversing selection to select all islands/land areas, and deleting those features.

  6. Clip the Thiessen polygon shapefile using the LDB water polygon
    1. Vector / Geoprocessing Tools / Clip

  7. Sort the output polygon using the original unique ID.
    1. Processing / Toolbox / Vector general / Order by expression
    2. Expression = ID
    3. Sort Ascending
    4. Save as new shapefile
  8. Confirm the resulting shapefile has the same number of features as the original .node file (open the attribute table and check the number of records).
  9. Save this shapefile in your MapLayerFiles and refer to it from Grids.xml.


  • No labels