 Hello, welcome back on my YouTube channel, in this video we're going to do a simple flood analysis. I'll start with adding OpenStreetMap from the browser panel to have some context, and I use the Locator bar to locate a city, in this example I'll use RotterDem. Zoom in to the area that you want to study. Now I'm going to install a quick OSM plugin, which I will use to download buildings from OpenStreetMap. Click this icon, and in the quick OSM dialog type for key building. Leave values as it is, so it will search for all buildings in the canvas extent. Expand the Advanced section, and make sure you only have multi-polygons selected in the right column, so we will only download building footprint polygons. Click Run Query. After it downloads all the buildings, close the dialog, and check the result. In the lower right of the screen I see that the on-the-fly reprojection is the Pseudo Mercator, while I want to work in the Dutch projection. So here I've changed the projection of the project, the on-the-fly reprojection, to the one of the Netherlands. Next I want to export the buildings to a geopackage using the correct projection. So select the geopackage, give it a layer name, and I changed the CRS to the one for the Netherlands, so the buildings will be reprojected from Pseudo Mercator to this projection. Click OK. Let's remove the temporary buildings layer, because we are going to continue with our geopackage building layer. The next step is to download the digital terrain model and the digital surface model of this study area. For this I will use the PDoc Services plugin. With the PDoc Services plugin you can get access to many open datasets for the Netherlands. After installation click the PDoc Services plugin icon, and there you see the list of layers that are available. AHN is the Dutch elevation model, and here you need the WCS layers for the digital surface model and the digital terrain model. Click one of the layers, and click standard to add it to the layers panel. This will take a bit because it's a large dataset. Now repeat this for the digital terrain model. If you choose boven it will arrive at the top, and if you click on there at the bottom of your layers panel. Here I choose boven because I want it at the top. This is a 50 cm elevation model available in the raster format so we can further process it. Let's clip the DTM and the DSM, and I use export, and I save it to this file name DTM RotterDem and then make sure that I use the map canvas extent so I clip the whole DTM to the map canvas extent and then I click OK. It will download all the pixels now. Remove the original layer and repeat the procedure for the DSM. Click write, use export save as, use the file name, take the extent from the map canvas extent and click OK. Let's have a look at the layers, open the layer styling panel, and remove the DSM, and what's always nice to visualize is using the hill shade, so I'll hide the layers that are below, and here you see that with the DTM the building footprints have been filtered out of the elevation model. So there we have the terrain, and with the DSM we can do the same, we visualize it with the hill shade, and there we see also the difference that with the DSM the buildings are present, also all the natural features like trees, but we need to interpolate our DTM if we want all the surface levels that are also below the buildings. So I'll use the fill no data tool from GDAL. With that tool you can interpolate no data values, which are called voids. So use the DTM as an input and change the maximum distance to 100 in this case, so we have a search distance that is enough to contain other pixels to base the interpolation on. So this distance is in pixels, and our pixel size is 0.5 meters. We don't need any advanced parameters and we save the result to dtmvoidsremoved.tif, then click run. Close the dialog, go to the layer styling panel and visualize the result as a hill shade, and compare it then with the original one, and here we see that most of the voids have been filled. Let's remove the original layer, and now we compare the DTM with the voids filled with the DSM. So here we see in the DTM that the buildings have been removed and the trees too. Now we can also have a look at the histogram. Click compute histogram, you will see here the distribution of elevations in this image, and you notice that there are several peaks. These peaks have to do with presence of dykes and polder levels that are at different heights. Now I'm going to calculate the slope to have an indication of the dykes, because the dykes should have steep slopes. I keep all the defaults here and I save the file to slope. Here we see the resulting grayscale, it looks a bit sketchy, go to the layer styling panel, there I use single-bamp pseudo-color, because it's a continuous roster, and I choose here the veritis color ramp, and this doesn't give us much contrast and a good way to increase the contrast here is to use a cumulative count, and there you see now in bright yellow the steepest features, which are our dykes. So this is a way to get more information about the structure of this polder area with dykes. We also see the tallutes of highways and other infrastructure. Next I want to extrude the buildings. Let's have a look at the layer properties and check the attributes. You can find the attributes under the information tab, and if you scroll down you see here all the fields that are available in the attribute table. There are two fields that can be used to extract the elevation, that's the height field and the building level field. However these fields are often not filled in and give an unreliable result. So in this video we're going to do it differently, we're going to use the DSM heights for giving the heights to the buildings. Go to the processing toolbox and search for zonal statistics. Double click the zonal statistics tool and make sure your input layer is the building layer and the raster layer from which we want to calculate the statistics is the DSM. Use the output column prefix of Z underscore and we are interested in the mean elevation per building footprint taken from the DSM and we will use that then as the elevation of the buildings. Save the result to the geo package and call it buildings with height. Click run. Click close after completion. I'm adding DTM void to remove under buildings with height and I hide other layers. I'm going to style the DTM now with single bump pseudo color and I'm going to save the project, save it as flats and I'm going to style the buildings with height and choose the 3D view, change it to single symbol and for extrusion I use the data defined override and I use the Z mean field that we've just used for zonal statistics and this will lift our buildings to the average elevation that was found in the DSM. Now I'm ready to use the 3D map view and here you see the extruded buildings in the landscape. In the layer styling panel you can also control the color of the buildings. Now I still need to configure that the DTM raster that is below uses the DTM elevation values and I'm increasing here the tile resolution to get some better detail. Click OK and now we can see the dykes in the landscape and the buildings and this gives us an impression of the elevation differences and the objects at the surface. The next step is to calculate the flood map. Double click on the DTM and use the less than or equal operator and type 1. So we'll select all the elevation values that are less than 1 meter and we will give that the value 1 for true and the other pixels the value 0 for false. In this way we simulate a sea level rise of 1 meters. This is the result. Let's style it to make more sense out of this and we use the pelleted unique values renderer because it's a Boolean raster. Remove the zeros and change the ones into blue so it corresponds with water. Now we see which areas in the city are flooded. You can also see which buildings have been damaged. Now I'm going to create a polygon from this flood raster and save the file to a shapefile and here's the result but it contains both the zeros and the ones. I go to the attribute table. I use select by expression and I choose dm equals 0 to select all the features that have zero so which are not flooded. Then I toggle the editing mode and I delete those features so I only have the flooded areas left over. Toggle off the editing and save the edits and also give this polygon a light blue color for water. You can here also reduce the opacity so we can see what is below. Of course we need to hide our flood raster and it's also nice to add an aerial photograph below and we use here the 8 centimeter aerial photograph and put it below. I hide some layers that were in between and there I see the flood extend over the aerial photograph. Now I would like to visualize the flood width 3D buildings in a 3D view. Instead of using the default 3D view of QGIS I'm going to use the QGIS to 3JS plugin. Hide all your layers and make sure only the OpenStreetMap layer is visible in the map canvas. Then click the icon to start the QGIS to 3JS exporter. Click the dtm void to remove layer and you will see here that the OpenStreetMap is visualized in a 3D view. You can use your mouse to navigate in the 3D view. Now go to scene and choose scene settings and there we can change a little bit the exaggeration to see better the elevation differences. So here I change it to 3 and click OK. The 3D view will render and here we see the result and now we see the dikes visible in the landscape. The next step is to go to the layer properties of the dtm and increase the resolution by increasing the resampling level and change the image width to 4096 which is the highest you can choose. Then click OK. If your computer cannot handle this you need to lower these resolutions. Here we see the result and we see much more detail here in the city and we can clearly distinguish the dikes here in the landscape. Now go to the layer properties of buildings with height and set the type from polygon to extruded. For Z coordinate use relative to dtm. For the geometry use the Z mean for the height, keep the rest as default and click OK. Now check the box to show the buildings. Now we have the buildings in 3D draped over our open street map which follows the digital terrain model. Now go to the layer properties of the flood polygon. Here also set the type to extruded. For the Z coordinate use the dn value which is 1 in this case which was true so 1 1 meter and for geometry I also use the 1 from the dn. If you use other elevations for the flood you of course need to edit the dn field with the flood height that you are using. And here is the result. We see in light blue with some opacity the flooded areas and let's maximize the screen and fly a bit through the landscape to see which areas are flooded. Of course the areas which have dikes or higher areas in general are not flooded but all the lower areas now are blue. I hope you've enjoyed this video and that this helps you to analyze floods in your own study area.