ManualV1 Using QGIS Mesh Preparation
ManualV1 Using QGIS Mesh Preparation
USING
FREELY AVAILABLE DATA AND SOFTWARE
Muluneh Mekonnen
(Global Institute for Water Security, University of Saskatchewan)
Abstract
This note provides a quick guide on how to prepare the MESH drainage database le using freely
available data as well as freely available software. The MESH drainage database le provides topog-
raphy and land cover information to the MESH hydrologic-land surface model. The note describes
processing of GeoBase's digital elevation and land cover data using Quantum GIS (QGIS), Envi-
ronment Canada's GreenKenue software and the 'bsn.exe' program to produce the MESH drainage
database le.
1 Introduction
This document is prepared to serve as a quick guide to build a MESH drainage database le using freely
available data as well as freely available software. The MESH drainage database le, a reformatted
version of the WATFLOOD map le, provides topography and land cover information to the MESH
hydrologic-land surface model. GreenKenue Ensim Hydrologic, 2007 requires digital elevation data and
land cover data to prepare the WATFLOOD map le. The 'bsn.exe' program converts the WATFLOOD
map into the MESH drainage database le. Quantum GIS (QGIS) is used to pre-process the eleva-
tion and land cover data. Stream network data (if available) can be used as predened channels (in
GreenKenue) to enhance ow direction calculations as well as the watershed delineation.
The Sturgis watershed is selected for illustration purposes. The outlet of the Sturgis watershed
(51.94N, -102.55W, Station No: 05MC001, and Station Name: ASSINIBOINE RIVER AT STURGIS)
is located near the border between Saskatchewan and Manitoba Provinces. According to Environment
Canada's HYDAT database the gross drainage and eective areas are 1930 km2 and 1140 km2 respec-
tively. The elevation of the watershed ranges from 640 m to 490 m. The Sturgis watershed is mainly an
agricultural area (crop land) and also consists of deciduous forest, wetlands and water bodies.
In this illustration the GeoBase website http://www.geobase.ca is assumed to be the main data source
and the GeoBase 250k map index (1:250,000 scale map sheets) are used to identify the map sheets that
cover the selected watershed. The document consists of four sections:
Software requirements,
Download and pre-process data using QGIS,
Prepare the Watood map le using GreenKenue, and
Prepare the drainage database le using the 'bsn.exe' program.
1
2 Software Requirements
This document and the procedures described are based on data processing under the Linux system
and WATFLOOD map generation and MESH drainage database le preparation under the Windows
operating system. Hence, modications may be required for other (combinations of) operating systems.
2.1 GreenKenue
GreenKenue, developed at the Canadian Hydraulics Centre (CHC), is an advanced numerical modelling
environment, as well as a general purpose data handling and visualization system that can easily be
adapted for any class of environmental data. It provides an ideal framework for the integration of
environmental data, GIS information and model data. One of the models supported by GreenKenue
is the WATFLOOD (Kouwen et al., 1993) hydrological model and hence GreenKenue allows importing
digital elevation and land cover data to create the WATFLOOD map le. GreenKenue is developed
for the Windows operating system but the 32bit version has been reported to install and properly
operate on a Ubuntu 10.04 Linux workstation using the Windows emulator wine 1.2+. The software
as well as the reference manual are freely available from National Research Council Canada website
http://www.nrc-cnrc.gc.ca/eng/ibp/chc/software/kenue/green-kenue.html. And installation under the
windows operating system is straight forward.
2.2 bsn.exe
The bsn.exe is a separate program that converts the '.map' le readable by the WATFLOOD model into
'.r2c' le format readable by the MESH model. The bsn.exe program can be downloaded from the HAL
website http://halfront.wxe.sk.ec.gc.ca/html/documents/store/1_3_sa_MESH.html
2.3 QGIS
The following description of Quantum GIS (QGIS) is as described in its ocial website http://www.qgis.org/.
"QGIS is a user friendly Open Source Information System (GIS) licensed under the GNU General Public
License (http://www.qgis.org/). QGIS is an ocial project of the Open Source Geospatial Foundation
(OSGeo). It runs on Linux, Unix, Mac OSX, and Windows and supports numerous vector, raster, and
database formats and functionalities."
QGIS can be freely downloaded and installed from the ocial website or the Ubuntu software manager
can be used to perform the same job.In this note QGIS is used for visualization purposes. To that end a
new symbology layer le is created (attached appendix). The data processing is performed on the com-
mand line (to be discussed later) using the GDAL and OGR libraries http://www.gdal.org/index.html.
Here follows description of GDAL library installation for Ubuntu.
Download FWTools (a set of Open Source GIS binaries for Windows (win32) and Linux (x86 32bit)
systems produced by Frank Warmerdam (i.e., FW)) from the link http://fwtools.maptools.org/.
FWTools contains a number of sub-packages out of which GDAL/OGR (a library and set of com-
mandline utility applications for reading and writing a variety of geospatial raster (GDAL) and
vector (OGR) formats) is of interest to this note.
Unpack the downloaded le and run the install.sh script in the directory where the unzipped le is
saved, and then add the bin_safe directory to your path. The following is an example of performing
this step for some version of FWTools. A few modications might suce for proper installation
and path setting.
% t a r x z v f FWTools−l i n u x − 0 . 9 . 5 . t a r . gz
% cd FWTools−l i n u x − 0 . 9 . 5
% . / i n s t a l l . sh
PATH=$PATH:$HOME/FWTools/ b i n _ s a f e
2
3 Downloading and Pre-processing Data
In this section downloading and processing of GeoBase's digital elevation and land cover data is presented.
This will be followed by step by step description of the dierent QGIS packages and commands that are
used to convert and reclassify the raw data so that it can be imported into GreenKenue.
Figure 1: Figure showing the GeoBase 250K map sheets that subscribe the Sturgis watershed.
Note that the LAT/LONG projection is used in preparing the Sturgis watershed MESH drainage
database le. However, the boundary shape le acquired is in UTM projection and the following com-
mand (from the OGR utilities) was used to convert to LAT/LONG projection (note: the target projec-
tion, t_srs, value of 4326):
ogr2ogr -t_srs EPSG:4326 OutputFile.shp InputFile.shp
And the general usage of ogr2ogr command is as follows:
Usage : o g r 2 o g r [−− help − g e n e r a l ] [ − s k i p f a i l u r e s ] [ − append ] [ − update ]
[ − s e l e c t f i e l d _ l i s t ] [ − where r e s t r i c t e d _ w h e r e ]
[ − p r o g r e s s ] [ − s q l <s q l statement >] [ − d i a l e c t d i a l e c t ]
[ − p r e s e r v e _ f i d ] [ − f i d FID ]
[ − s p a t xmin ymin xmax ymax ]
[ − a_srs s r s _ d e f ] [ − t _ s r s s r s _ d e f ] [ − s _ s r s s r s _ d e f ]
[ − f format_name ] [ − o v e r w r i t e ] [[ − d s c o NAME=VALUE] . . . ]
dst_datasource_name src_datasource_name
[ − l c o NAME=VALUE] [ − n l n name ] [ − n l t type ] [ l a y e r [ l a y e r ...]]
As shown in Figure 1 the 1:250,000 scale map sheets of 062M and 063D cover the Sturgis watershed.
Follow the procedures below to produce a unied DEM that can be imported into GreenKenue.
3
Download 062M and 063D from GeoBase digital elevation data,
Unzip the downloaded les and make sure that the following dem les are available:
062m_0100_deme.dem
062m_0100_demw.dem
063d_0100_deme.dem
063d_0100_demw.dem
Merging mosaic of grids into ArcInfo ASCII grid (Merge the grid les to a format that supports di-
rect creation and random writing such as GeoTIFF (driver name GTIFF) or Erdas Imagine (driver
name HFA) using the gdal_merge.py command):
gdal_merge.py -o STURGISDEMTIFF 062m_0100_deme.dem 062m_0100_demw.dem 063d_0100_deme.dem
063d_0100_demw.dem
Use gdal_translate to convert to AAIGRID. Some drivers, such as the AAIGRID driver can only
operate by copying from a preexisting le:
gdal_translate -of AAIGRID STURGISDEMTIFF STURGISDEM.grd
The processed DEM is as shown in Figure 2 with a zoomed view as shown in Figure 3.
4
073H 063E 063F
063D
Figure 2: Figure showing Downloaded,formatted and stitched DEM map of the Sturgis watershed.
062M
3.2 Land Cover Data
Again using the same scale for the land cover (the 1:250,000 scale) the map sheets of 062M and 063D
cover the Sturgis watershed. Follow the procedures below to produce a unied Land Cover that can be
imported into GreenKenue.
Download 062M and 063D from GeoBase Land Cover data 1:250,000 scale map sheets.
Unzipping the downloaded les will produce the following Land Cover vector maps:
LCC2000-V_062M_1_0.shp
LCC2000-V_063D_2_0.shp
Merge the above shape les into a single shape le using commands from the OGR utility:
* create a new shapele STURGISLANDCOVER and copy the contents of LCC2000-
V_062M_1_0 into the new shapele,
ogr2ogr STURGISLANDCOVER.shp LCC2000-V_062M_1_0.shp
* append the contents of LCC2000-V_063D_2_0 to the newly created shapele and name
it STURGISLANDCOVER.
ogr2ogr -update -append STURGISLANDCOVER.shp LCC2000-V_063D_2_0.shp -nln
STURGISLANDCOVER
The stitched Land cover data should resemble Figure 4. The symbology is based on the harmonized
legend build by the Earth Observation for Sustainable Development (EOSD). A symbology style
(provided in Appendix A) is prepared to reproduce the QGIS version of the GeoBase's symbology
layer that is applicable for ArcGIS. The following set of commands (this is applicable using the
QGIS 1.4 graphical interface) can be used to load the style:
Select the text in Appendix A (or ask for the le from HAL) and save it with extension '.qml',
Select (click on) the shapele in the table of contents (TOC),
Right click and choose 'Properties',
Choose the 'Symbology' category,
Click on 'Load Style...',
Select the saved qml le and click 'Apply' or 'OK'.
6
Figure 4: Figure showing Land Cover data of the Sturgis watershed.
3.3.1 Use SQL Query Builder to select land covers for each group
In this exercise (based on the Geobase's EOSD and as indicated in the qml text) values for the
attribute eld (COVTYPE) that can be grouped into the crop land are all less than 200 excluding
wetlands (COVTYPE >= 80 and COVTYPE <= 83), ice (COVTYPE = 31) and water (COV-
TYPE = 20). Hence the following procedure was used:
Right click on the land cover (in the TOC) and click on the 'Open Attribute Table',
Click on 'Advanced Search',
7
Write the following clause in the 'SQL where clause' space:
COVTYPE < 200 AND COVTYPE != 20 AND COVTYPE != 31 AND COVTYPE != 80
AND COVTYPE != 81 AND COVTYPE != 82 AND COVTYPE != 83
Click 'OK',
Again right click on the land cover (in the TOC) and click on the 'Save selection as shapele'.
The above procedure should produce the Figure shown below (Figure 5). Note that the clipping is
done using the 'Vector' menu of QGIS where the 'clip' tool is available in the geoprocessing package
(sub menu).
Figure 5: Figure showing land cover types for the crop land class.
Values for the attribute eld (COVTYPE) that can be grouped into the Deciduous Forest are all
the rest than those included for the crop land. Hence the following procedure was used:
Right click on the land cover (in the TOC) and click on the 'Open Attribute Table',
Click on 'Advanced Search',
Write the following clause in the 'SQL where clause' space:
COVTYPE >= 200 OR COVTYPE = 20 OR COVTYPE = 31 OR COVTYPE = 80 OR
COVTYPE = 81 OR COVTYPE = 82 OR COVTYPE = 83
Click 'OK',
Again right click on the land cover (in the TOC) and click on the 'Save selection as shapele'.
8
The above procedure should produce the Figure shown below (Figure 6).
Figure 6: Figure showing land cover types for the crop land class.
Producing the above two gures helps to make sure that the SQL query is done the right way.
Coming back to the main point (that is to produce a single reclassied shape le) we need to
edit the 'COVTYPE' attribute eld such that it will only has two values for the two classes, crop
(COVTYPE=1) and forest(COVTYPE=2). Again the following sets of commands can be executed
using the QGIS interface (the procedure should have been simplied with an automated script to
run on the command line):
Use SQL query to select land covers for the crop class (use the above procedure with the 'SQL
where clause' space: COVTYPE >= 200 OR COVTYPE = 20 OR COVTYPE = 31 OR
COVTYPE = 80 OR COVTYPE = 81 OR COVTYPE = 82 OR COVTYPE = 83),
Click on 'Toggle editing mode'. The icon for the 'Toggle editing mode' can be found either
on the main interface of QGIS or in the opened attribute tables dialogue,
Click on 'Open eld calculator' in the opened attribute tables dialogue and assign a value of
1 for the selected features in the 'COVTYPE' attribute eld, and
Using a similar procedure assign a value of 2 for the remaining features in the 'COVTYPE'
attribute eld.
The reclassied shape le should produce a similar Figure as shown below (Figure 7).
9
Figure 7: Figure showing reclassied shape le (the crop and forest land classes).
0.00088332426008727594
0
0
− 0.00088332426008727594
− 103.26752961654286
52.472087875330367
10
The nal two values are the X and Y location of the centre of the top left pixel. The information
in this le should be properly used when importing the 'ti' le into GreenKenue so that it
will be positioned at the right location and with the right extent.
Import the DEM as ArcINFO Grid (ASCII) (File Import ArcINFO Grid (ASCII)). It may
be good to provide '.asc' extension for the DEM le. Also, check the header of the DEM le.
The 'NODATA_VALUE' line may be absent. In that case include 'NODATA_VALUE -9999'
at the end line of the header,
Once imported click on the le in the TOC. Right click and select 'properties'. Click on the
spatial tab and assign the coordinate system as LatLong projection and WGS84 datum,
Import land cover as GeoTIFF (File Import GeoTIFF),
Once imported click on the le in the TOC. Right click and select 'properties'. Click on the
spatial tab and use the information from '.tiw' world le for the South West location as well
as for the grid sizes. Note that the world le provides the North West location and with a
negative grid size for the Y direction. It is recommended to calculate the corresponding South
West location and use a positive grid size. Click 'Apply' and assign the coordinate system as
LatLong projection and WGS84 datum.
Further reclassify the land cover le using 'Reclassify' from the 'Tools' menu and make sure
that the two land classes are properly represented.
11
Figure 8: DEM and reclassied land cover data of the Sturgis watershed (in GreenKenue).
From the 'File' Menu select 'new' and click 'watershed le' (File new watershed), a new
dialogue will appear and a watershed object will be created in the TOC,
Drag and drop the DEM into the child dem of the new watershed,
Select the 'watershed' tab from the opened workstation dialogue and click 'generate', stream
network and an arbitrary bigger basin will be generated,
Drag and drop generated stream channels into the 2D view,
Pick a point at the outlet of the Sturgis watershed,
Right click and click on 'add basin', delete the bigger basin that was generated in the rst
step.
The generated basin boundary should appear as shown in Figure 9. Blue is the Sturgis watershed
boundary from PFRA and red is boundary generated by the GreenKenue algorithm.
12
Figure 9: DEM and reclassied land cover data of the Sturgis watershed (in GreenKenue).
13
attributes of the map le using the GreenKenue graphical interface. Double clicking the map object
in the TOC will bring a new window where we can select the 'data' tab that lists down all the
attributes. Figures of four important attributes (DEM, drainage directions, area fraction of the
crop class and area fraction of the forest class) of the Sturgis map les are provided below. Try to
compare the values with the corresponding original data.
14
Figure 11: Sturgis drainage directions representation in the generated map le.
Figure 12: Sturgis crop class representation in the generated map le.
15
Figure 13: Sturgis forest and water bodies representation in the generated map le.
The MESH drainage database le is the reformatted version of the WATFLOOD map le. There
is a windows based executable le (bsn.exe) that does the reformatting. Further details on how to
use the program can be referred to the MESH manual. The bsn.exe program has not been updated
for a while where as GreenKenue has been continuously updated. Hence there are a few steps to
be done on map le before using the bsn.exe program:
Go to the directory where you saved the map le. Rename the map le using a short name
(may be less than 7 words).
Open the map le using any text editor and correct formats in a few lines (see the correction
made for the Sturgis map le below): On line 2 and 3 provide spacing between the attribute
name and the value (i.e., for :Projection and for :Ellipisoid), Change Latlong to uppercase
LATLONG, and delete the repeated comment on line 8.
#
: Projection Latlong
: E l l i p s o i d WGS84
#
: xOrigin − 103.440600
: yOrigin 51.735800
#
#
: xCount 6
: yCount 6
: xDe lta 0.219000
: yDe lta 0.135000
#
: contourInterval 1.000000
: imperviousArea 0
: classCount 2
: elevConversion 1.000000
16
#−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
: endHeader
And here is the corrected header for the Sturgis map le.
: Projection LATLONG
: Ellipsoid WGS84
#
: xOrigin − 103.440600
: yOrigin 51.735800
#
: xCount 6
: yCount 6
: xDe lta 0.219000
: yDe lta 0.135000
#
: contourInterval 1.000000
: imperviousArea 0
: classCount 2
: elevConversion 1.000000
#−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
: endHeader
Now the corrected map le is ready and we can run bsn.exe program. It is preferable to run the
program on the dos command line.
Carefully follow the printed message on the screen and provide the right input. At the middle
of the process bsn.exe will conrm if the map header is read right as shown in Figure 15,
17
Figure 15: bsn.exe program conrming if the header is properly read.
If there is inconsistency then try to gure out what is wrong in the map le and run the
bsn.exe program again,
If every thing is right then the program will end normally as shown in Figure 16 and will
produce many les,
Out of the many les produced by the bsn.exe program it is the 'new_shd.r2c' le that is required
for the MESH modelling. Save the le as 'MESH_drainage_database.r2c' and with that we are
all done using freely available programs and freely available data.
References
N. Kouwen, E.D. Soulis, A. Pietroniro, J. Donald, and R.A. Harrington. Grouped response units
for distributed hydrologic modeling. Journal of Water Resources Planning and Management,
119(3):289 305, 1993.
18