 Hello. I'm Stacey. I'm a GIS analyst with the Natural Capital Project, and I'm glad that you've joined me to learn some techniques for working with the geospatial data that's used by the Invest Ecosystem Services Modeling Toolkit. This episode provides an introduction to working with digital elevation models. To get the most out of this tutorial, I highly recommend following along in your own GIS session. In this video, we will demonstrate techniques in QGIS, and we'll be working with some sample data. And that sample data is linked to on the webpage for this video. In several previous episodes, we worked with data in Nepal, so we will continue with that location in this video. If you happen to have a QGIS session saved from those earlier episodes, then you can use it again now. If you don't, that's totally fine too. You can just open up a new session. So if you haven't already, now is a good time to pause this video, download the sample data, unzip it, and bring up a QGIS session before continuing. A digital elevation model, or DEM, is a raster with an elevation value for each pixel. A DEM is required by the freshwater models NDR or nutrient, SDR or sediment, and seasonal water yield. And for these models, it's very important that the DEM represent the areas hydrology correctly. Coastal vulnerability also requires a DEM, but it's not as important to get the hydrology correct for that model. Now a DEM can be obtained from many different sources. And often these sources have global data coverage like NASA or hydrogens. If you compare multiple DEMs in the same location, you'll find that each one is different, some more accurate than others in that particular place. Then if you look at a different location, you may find that some other DEM is more accurate. So they are highly variable. But one thing that is pretty much guaranteed is that none are perfect. I have never found a DEM that perfectly matches a real-world stream network, and many don't even come close. So be aware that you may need to try several different DEMs before finding one that works well enough for your purposes. Regardless of the DEM that you decide on, you'll probably need to do several steps of preparation before it's ready to be used with an investment model. These steps include merging raw DEM data into a mosaic, checking for holes or missing data, projecting to whatever you've selected for your analysis coordinate system, filling sinks, verifying the stream network, and creating watersheds. In this tutorial, we will work through the first four of these steps. And to keep each episode from being too long, we'll cover next steps like creating the stream network and watersheds in separate videos. Along with this video, the Invest User Guide has a section called Working with the DEM, which provides an overview of the different steps involved, as well as the methods and GIS tools that can be used. A link to that User Guide chapter is included in this video's webpage. All right, let's go to a GIS session and work through some of these steps. Open a file explorer window to the folder containing our sample data. It's called Preparing the DEM data. And inside of this folder are five rasters with Aster G DEM data, which I downloaded from NASA, the US Space Agency, which provides several global DEM products. Let's drag and drop all of these into the GIS. Because DEM data can be pretty large, it is often broken up into smaller tiles. And so often, we need to download multiple tiles to cover our study area. In this case, we need five tiles to cover the whole watershed that we're modeling. Because the Invest models require just a single DEM raster as input, we'll need to combine these tiles into one raster. To do this, we'll use the Merge tool. So we'll go to Raster, Miscellaneous, and we'll open up the Merge tool. For input layers, click in this box to the right of the window, and then click the Select All button. To go back to the original window, we'll go up here to the left and click on this blue button. For output data type, we need to choose the same type that the input rasters have. So right-click on one of the tiles. It doesn't matter which one. And select Properties. And then click on the Information button. Looking at the data type value, we see that it is a 16-bit signed integer. So that's what we need to use for the tool. So back in the tool under Output Data Type, we will select Int 16. All right, under Advanced Parameters, the first one says the input value to treat as no data. From reading the Aster GDEM documentation, which is included in our sample data, I learned that they used a value of minus 9999 for what they call void pixels. So we'll specify that same value of minus 9999. The next input is Assigned Specified No Data Value to Output. Now, it is important that we do set a no data value for all rasters that are used in Invest. The model itself doesn't really care what the actual no data value is. But if no value is set, it can cause errors in Invest, which are often hard to diagnose. The only thing that we want to make sure is that whatever value we choose, it is not actually valid elevation data. Now, I have to admit that I've had a hard time getting QGIS to handle no data correctly. But one thing that seems to work in this moment is to set the no data value to minus 32768. And that is the maximum negative value for an Int 16 raster. So our no data, the input pixel value to treat as no data, is minus 9999. And the output no data value is minus 32768. All right. So now if we go down some more, this entry called merge is where we specify the output filename. Click the button to the right of the entry and say save to file. Navigate to the folder where you want to save your tutorial data. I'm going to save mine in the same place where I have the sample data. And I'm going to create a new output folder there. So I'm going to do a new folder and I'm just going to call it dem underscore output. And I'm going to go inside of this folder and create the output filename dem underscore mosaic.tif. And I do recommend using TIFF files for your rasters and invest. All right. So click save. And now we can click run. All right. Now we have a stitched together dem raster. If we turn this on and off, we can see how we no longer have these edges. Very obvious, like we do in the original tiles, right? The edges seem to have been stitched together correctly. But then we notice that the minimum and maximum elevation values don't really correspond very well with the min and max values of the tiles. This is because of how QGIS symbolizes rasters by default. So let's right click the merged raster and select properties. And then click on symbology. All right. What we need to do is click on the min, max value settings. And at the top here, make sure that min, max is selected, like mine is. The statistics extent should be whole raster. And then the accuracy should be actual. And click OK. And you see how the numbers have changed. Now they correspond much better to the minimum and maximum values that we find in the tiles. One thing that's worth doing at this point, and this is what we would do in real life, is to make sure that there are no holes or areas of missing data in the map. Unfortunately, I haven't found an easy way to do this in QGIS. So I'm going to leave this as an exercise for you to figure out. One way to do it would be to create a background of very bright pixels so that you can see, and it's highlighted, where any missing data might be. Now if we do find no data values within the study area, then we need to consider how to fill them. And since having holes can cause problems with the hydrology models, sometimes it causes them to throw an error. And even if there is not an error, the missing data will interrupt the flow path in that part of the watershed, leading to incorrect results. And working with data holes is a whole other world that we won't get into now, since it's not required very often. But you can get ideas for how to deal with them by reading the user guide section, working with the DEM. All right, the next step is to reproject the mosaic DEM to have the same projected coordinate system that we're using for our analysis. In QGIS, reprojecting is done using the warp tool. So let's open that by going to raster, projections, and warp. The input raster is the mosaic DEM that we just created, which I call DEM mosaic.tif. So make sure that that is selected. Now the tool will automatically detect the source CRS for us, and CRS stands for coordinate reference system. So we don't need to specify that. But we do need to choose the target CRS. Now let's click in the box to the right of this entry. Now at the top of this window, let's uncheck this box that says no CRS, because we want the rest of this window to be active. We talked about coordinate systems in a previous episode. So suffice to say that it's up to you to choose the projected coordinate system that you'll use for your project, and make sure that all of your spatial data uses it. One very standard system is UTM, and that's what we'll use now. Now our study area in Nepal is in UTM zone 45 North. So one easy way to find this is to type this into the filter bar at the top of the window. UTM zone 45N. Now down here below, a list of values will appear with several options to choose from. Now if we scroll down, we actually want the last one in the list, this WGS84 UTM zone 45 North. If we click on that, it will show a map of where that UTM zone is in the world, which looks about right, and that's a very cool feature of Q. So let's click OK to close that window. Next we'll choose the resampling method to use. In this case, it is very important to select a different resampling method. By default, the tool will use Nearest Neighbor Resampling, and that works great for categorical data like land use, and it can be used in many cases, but it should not be used for resampling DEM data. If you resample with Nearest Neighbor, the hydrology layers that are derived from the DEM, like flow direction and flow accumulation, will probably have a weird grid pattern to them that is very incorrect, and it leads to the creation of bad flow patterns, bad streams, and bad model output. So I usually use bilinear, and I'm going to select that now, but cubic also works. You're also free to try out any of these other options, but I have found bilinear and cubic to work the best for me. But we'll choose bilinear right now, and this time the tool will automatically detect our no data value, so we don't need to specify that. If we scroll down, we do need to specify the output file resolution, which will be given in meters. From reading the Astro G DEM documentation, which is included in the sample data, I know that the data resolution is 30 meters. So let's type the number 30 in that box. It's a good time to note that the freshwater models that use a DEM, so SDR, NDR, and seasonal water yield, they will resample all of your other spatial inputs to match the resolution of the DEM, and your output rasters will have the same resolution as your DEM. So all of your output is based on the resolution of the DEM. All right, next we'll define our output data set down here in the entry called re-projected. So let's click on save to file, and again, I'm going to save this in the same DEM output folder as the mosaic, and I'm going to call this data set DEM underscore projected.tif. Now let's click run. All right, the output raster here, DEM projected, has slightly different high and low values than the mosaic did. That's a result of the bilinear resampling that's done during reprojection, and usually that's okay. The last thing we'll do in this tutorial is fill syncs in the DEM. Syncs are errors in the DEM data, where one pixel is much higher or lower in elevation than the pixels around it. And syncs cause all sorts of problems when modeling hydrology, and we can usually fix them using the QGIS, Wang, and Lu Feel tool. To find this tool, select the processing menu, and then open up the toolbox. Up in the search window, type fill syncs, and you'll see that we have several options to choose from. The one that I recommend using is Wang and Lu. So let's double click on that to open it. The input DEM is the projected layer that we just created, so make sure DEM projected is selected. And then going down to the filled DEM input, we'll click on save to file, and once again, we'll save things in the same output folder as our other rasters. And I'm going to name my file DEM underscore fill, but normally, I would create a TIFF file for my output, but for some reason, this tool only lets us output sstat. We can easily export sstat to TIFF afterward, so we're going to name the file DEM sfill.sstat, and click save. All right, for now, we won't generate flow directions or basins, so uncheck the boxes next to those, but do keep the checkbox next to open the output after running algorithm underneath your fill down. All right, let's click run. The fill tool can take a while to run, especially if the DEM is very large or it's very high resolution. Now, you may have noticed that there are several other fill tools available. You are welcome to use any of these, but we do recommend Wang and Lu since we've found that it does a particularly good job, and it generally produces results that work well and invest. So, I'm going to hang out here while the tool runs. Feel free to pause this video and return when yours is finished. All right, once that's done, we can once again look at the high and low values for the output raster. It looks like the lowest value is now much different. It's 63 instead of 9, so the tool seems to have filled the pixels with the lowest elevation values. Now, let's click on and off the filled layer. Do you see the very dark spots right in here that are in the projected layer but not so visible in the filled layer? Let's zoom into one of them. I'm going to zoom into this area right here and we're going to see what's going on. Using the identify tool, let's look at the projected layer, not the filled layer yet, the projected layer, and let's click inside one of these dark areas with low elevation values. Now, in the case of the pixel I clicked, it has an elevation value of 558 meters in the original data. Just outside of that dark area, the elevation is 5200 meters. That's much, much larger. That's a big difference and it's probably not what's actually happening on the landscape. Let's turn on the filled layer now and let's see what the new value is. Inside of this dark area, it's now a value of 5128 meters and that seems much more reasonable, keeping in mind that this is the Himalaya. To verify, you could use a satellite base map to visually inspect this area, but we won't do that now. You can do that on your own for homework. The last thing we'll do is export the sstat file to a TIFF for use in and best. To do this, we'll right-click on the filled layer and select export and save as. By default, the format is geotiff and that's what we want. For the file name, we'll navigate to the place we're saving our data and I'll call the file DEM underscore fill.TIF. That's all we need to do and we can hit OK. That's enough for this session. Now that the DEM is prepared, the next steps involve creating a good stream network and delineating the watershed that is your area of interest and we will cover these in future episodes. If you have any questions or comments about this episode, we'd love to hear from you on our community forum. There's a link to the forum in this video's webpage where you can search for previous posts and create a new post under the category of training. I and other techies at NatCap will see your post and we'll respond as soon as we can. Thanks for following along.