Preparing Global DEM Data For QSWAT Chris George March 2015
Preparing Global DEM Data For QSWAT Chris George March 2015
Preparing Global DEM Data For QSWAT Chris George March 2015
Chris George
March 2015
Version 2
1 Introduction
You may have your own digital elevation map (DEM) for your watershed, but if you don't this
document explains how to obtain and prepare DEM data obtainable free from the web. The techniques
for clipping and reprojecting DEMs may also be useful for DEMs from other sources.
There are also notes about masking DEMs and about dealing with large DEMs in the final two sections
that should be of general interest.
Under Coordinates, select Decimal and click Add Coordinate. Enter, the latitude and longitude of one
of the 4 corners of the extent. Add the other 3 corners similarly. Then above Enter Search Criteria
select the second tab, Data Sets.
Find Digital Elevation, click on the plus sign to expand and find SRTM. Expand that and check SRTM
1 Arc-Second Global. Then go straight to the fourth tab, Results.
After a few seconds you should see the tiles you need listed. For each one. Click on Download options
(the 5th symbol) and then click Download beside GeoTIFF. Save the file, close the Download Options
form, and repeat for each of your tiles. Note that the save form says the file is a zipped archive, but its
extension is .tif and it is not zipped. Move the .tif files to the map folder.
3 Clipping the grids
Start QGIS and load the first grid (using Layer Add Raster Layer, or the corresponding button on the
left of the QGIS window). Select Raster Extraction Clipper to bring up the Clipper form
(Figure 1). Set the grid to the Input file, type <grid_name>_clip_ll as the Output file, check No data
value, and enter the appropriate value, which is -32768 for 90m data and -32767 for 30m data1. You
can find the appropriate value by right clicking on the entry in the Layers panel, selecting Properties,
and selecting the General tab. The no data value is included in the Layer info box.
Use Extent as the Clipping mode, and enter the extent you used to download the grids. It is a good idea
to widen these somewhat, say by 0.2 of a degree, to make sure there are no problems. x here means
longitude and y is latitude. Make a note of the values you use as you may need them again. The
extent will be shown as a rectangle on the map canvas, so you can see it is where you expect it to be.
Check Load into canvas when finished and click OK. You may get a warning about going outside the
raster, which you can ignore if this is what you expected. Don't close the Clipper form, so that you can
keep the no data value and extent. Right click on the original, unclipped grid in the Layers panel,
select Remove and confirm. You will be left with the clipped portion. Load each of the other grids, and
clip in the same way. Remember to change the output file name each time or you will overwrite a
previous clip. Close the Clipper form when you have clipped all your grids and checked that the pieces
abut to form a rectangle as expected.
1 The value should not matter, as long as it is less than any occurring in the actual data, but if it is different from the
existing no data value it can cause problems with the existing value being accepted as an actual data value.
4 Merging the grids
You should have all the clipped grids loaded. Use Raster Miscellaneous Merge to open the
Merge form (Figure 2). Click the Select button next to Input files and in the next form navigate to the
map folder. Hold Ctrl and click on each of the files ending in _clip_ll.tif. Click Open. You will be
back in the Merge form. Click Select by Output file, which should return you to the map folder, else
navigate to it, choose a suitable name, perhaps ending in dem_ll to remind you what it is, and click
Save. Back in the Merge form, check No data value and enter the value you used earlier, e.g. -32768
for 90m, -32767 for 30m. If necessary, check Load into canvas when finished, and click OK. Check
the next two messages don't tell you of errors, and click OK to close each of them.
Check your merged DEM is OK by removing the visibility of the other layers. If all is well you can
Close the Merge form.
Start a new QGIS instance (leaving the old one in case you find you made an error and need to redo
something). Load dem_utm file and check it looks OK. Note that coordinates in the box at the bottom
are now shown as metres instead of degrees (you won't recognise the numbers but you will see the
difference from the previous instance of QGIS)2. If all looks well close the previous instance of QGIS.
Choose Discard when asked if you want to save the project.
6 Masking a DEM
QSWAT does not itself provide a facility for masking a DEM, because the capability is already in
QGIS. Before showing how to mask, a note about when to do it. Masking, or reducing the area of the
2 If you see degrees instead of metres as the coordinates you should open Project Project Properties and select the CRS
tab. If Enable 'on the fly' CRS transformation is checked you are strongly advised to uncheck it. If it is checked then
you will not be informed about loading layers with different projections, which can lead to errors in QSWAT.
DEM to be delineated, is done for two reasons:
1. To reduce the amount of time that delineation takes.
2. To improve the accuracy of delineation.
The first reason is much less true now than it was some years ago because of the improved speed of
computers. Unless your DEM is very large and detailed it will typically take a few minutes at most to
delineate, and as you don't often repeat the process (and QSWAT tries to reduce the amount of
recalculation when it is repeated, as well as supporting multi-core processing) reducing the area more
than the rough clipping described in this document is not likely to be worth doing. See section 7 for
more information about large DEMs.
Masking is also dangerous. If after delineation you find that part of your watershed boundary is on the
edge of your DEM then it is quite possible that you have excluded some of the watershed, and it will be
a good idea to reclip the DEM more generously and run again. So the general advice on masking your
DEM is don't do it!
The second reason is much more compelling. DEMs are far from perfect representations of the real
terrain, and can easily include in the watershed areas which are known to be outside it. In this case, if
you have a reliable map of the actual watershed boundary, you can use it to clip the DEM precisely.
So we assume you have a good map of the watershed boundary, which we assume is a shapefile with a
single shape in it. We further assume it is in the projection of your final DEM: if it is in some other
projection right click on the entry in the Layers panel, select Save as..., and in the next form change the
CRS from Layer CRS to Selected CRS, use Browse to find the projection, enter a new file name and
click OK (Figure 5).
We can now use this boundary shapefile to clip our DEM. Start QGIS, load the projected DEM, and
then load the projected watershed shapefile (Figure 6) Check the shape lies within the DEM, or we
made a mistake somewhere!
Figure 6: Ready to clip DEM with watershed boundary shape
Then use Raster Extraction Clipper to open the Clipper form (Figure 7). If not already selected,
select the dem_utm from the pull-down menu as the input, Click the output Select button, navigate to
the map folder, and use perhaps sj_dem_clip_utm as the file name. Set the no data value to that of the
DEM, -32768 for the 90m, -32767 for the 30m. Set the Clipping mode to Mask layer and make sure
the boundary shapefile is selected Click OK to reproject, and again to clear the completion message.
Figure 7: Clipping the DEM by mask
Close the clipper form and remove the dem_utm to check that we have a DEM clipped to the shape.
7 Large DEMs
Some processing times for large DEMs are shown in Table 1. These are not intended to be anything
more than indicative: while the number of cells in a DEM is probably the main factor influencing
processing time, it is not the only one. DEM sizes are in millions of cells: for example the 100 million
DEM has 10000 rows and 10000 columns. You can see the size of your DEM by loading it in QGIS,
right clicking the entry in the Layers panel and selecting Properties. The Layer info section under the
General tabe shows the number of columns and rows.
The times in Table 1 are for running from after loading the DEM to the end of stream delineation: this
includes the two most long-running TauDEM functions (D8FlowDir and DinfFlowDir) Note that these
two functions only need to be rerun if the DEM changes. If you want to change the delineation
threshold, or the inlets/outlets, the rerun will be much faster than these times. Where there is a second
time in brackets, this is for running without using the Message Passing Interface (MPI), i.e. with a
single process. The machines used to obtain these figures are:
A. A 32-bit laptop with an Intel T9400 2.53GHz processor with 2 cores and 2 GB of memory. MPI
was used with 4 processes.
B. A 64-bit PC with an Intel i3 3.3GHz processor with 2 cores, 4 logical processors and 6GB of
memory. MPI was used with 8 processes.
C. A 64-bit PC with an Intel i7 3.4GHz processor with 4 cores, 8 logical processors and 8GB of
memory. MPI was used with 16 processes.
Machine/ A B C
DEM size
100 2100(*) 255(560) 104(450)
25 *(480) 64(140) 28(111)
12 159(205) 28(61) 12(48)
6 42(57) 8 (16) 4 (13)
4 13(22) 3(5) 1(3)
2 7(9) 1(2) 1(2)
1 3(4) 1(1) 1(1)
Table 1: Times in minutes for processing large DEMs (sizes in millions of cells)
* - run failed
There are two conclusions to be drawn from these figures:
In this range of DEM sizes the times increase initially linearly with the size of the DEM, but
later much more sharply. A DEM of 369 million cells processed on machine C took over 15
hours, much worse than the rough '1 minute per million cells' that you would expect for this
machine from the table. Typically 'Not Responding' will appear at the top of the main QGIS
window and/or the delineation form. This is a result of the TauDEM processes running in the
background but using almost all the CPU resources. Ignore the lack of responsiveness and be
patient!
MPI only makes a substantial difference when the DEMs are above a few million cells.