 Hello, I'm Hans van der Kwas, lecturer at IHG Delft Institute for Water Education. In this video, I will explain more about raster processing. After this lecture, you will be able to describe different raster data types and how they are used, and how to use map algebra for geoprocessing. The concept of map algebra was introduced by Dr. Dana Tomlin in the 1980s. In this concept, raster layers are considered as objects that we can use in mathematical calculations like we do algebra, therefore it's called map algebra. And we can use map algebra for multiplication, divisions of maps, all the mathematical things that we would do with a calculator. But we can also use it for functions. So in a desktop GIS, you will find this functionality in a raster calculator. But this can also be used in a command line or a script. Map algebra uses specific syntax. So when we use mathematical operators, we write that the result equals an expression and then the operator plus, minus, multiplication, etc., and another expression. And these expressions can be maps or something that results in a map. And the result is normally a map. The use of the syntax becomes clearer if we look at examples. In the first example, we are going to multiply two maps. So map A is the result map and that equals map B times map C. So here we have the maps with the values. So we can see that if we look at the pixel in the middle, that in map B it's eight and we do it times seven in map C. And that results in 56, which will be stored in the same location in the cell of map A. We can also multiply maps and do additions by following the mathematical rules. So in fact, the algebraic rules are similar for map algebra as for normal algebra. Apart from mathematical operators, we can also use functions. And then the syntax is a little bit different. We have a result map that equals the name of a function, a GIS function, and then the expressions, which can be maps or other things that result in a map. And the result is a map and sometimes it can be multiple maps. An example of a function is the slope function. So if we have a digital elevation model, it's a map with elevation values, we can apply the slope function and the result will be stored in a map. In this case, it's called slope map. In map algebra, we have different types of operations, which I'll explain in the next slides. There are local or point operations, there are focal or neighborhood operations, there are zone or area operations, and global or map operations. Local operations are map algebra operations that are independent of neighboring cells. So they are evaluated cell by cell, like the example of the multiplication. And the result map is then the result of the calculation for each specific location. Examples are simple mathematical operations like adding two maps, or a more hydrology related example. If we want to calculate the depth to groundwater, we take the raster that has the elevation of the surface and we subtract the groundwater level. And then we have the distance or the depth to the groundwater level. And we can do all kinds of mathematical operations in this way, like conversion of units, for example. With focal operation, it's a bit different, because there is a relationship between the cell that we consider for the calculation and its surroundings. There are different types. There are window operations, where we look in a fixed area around the cell. And that area is called the window. There are flow direction operations, where we consider the flow direction to calculate the result of the pixel. Friction path is a bit similar, but then not related to flow, but to frictions. And there's transport of material over the flow direction, where we consider a flow path of the materials. And there's visibility analysis, which can be used to calculate what you can observe from a certain point. Here I present some examples of focal operations. Let's say you have an elevation map, and you want to have the average elevation in 3 by 3 kilometers around the pixel that we consider to smooth the elevation data. There we can use these focal functions. So here the window average is a certain function that will average the elevation values in a 3 by 3 kilometer window, as specified by the value 3000. And the result is stored in the average elevation map. Another example is if we want to look at habitat diversity. So we have a map of habitats. And in a 5 by 5 kilometer window, we calculate how many different habitat types are there. And that result is stored in the diversity map. The slope map is also an example of a focal operation. If you have an elevation map, then we consider a window of 3 by 3 pixels to calculate the steepest slope. And that is assigned to the center of the window. More information about this operation can be found in the video on DEM analysis and catchment delineation. An example of using the flow path is this, where we have as an input rain, which we have some unit conversion. So we do times 1000. And we have a flow direction map or a local drain direction map. And the function aquiflux accumulates the material. So the 1000 times rain millimeter over the flow direction to get the flow accumulation. Then there are zonal operations. Zonal operations are related to classes to which the pixel belong. And it can be used to aggregate the cell values over areas. So we can calculate the average or the total per land use class, for example. Let's look at the examples. As input, we have a continuous map and a discrete map. The continuous map in the first example is temperatures. There's gradients in the landscape of temperatures. And we want to know the average temperature per land use type. So we average over the land use classes and that will give us the class average. In hydrology, we often need to prepare maps for our models, which also have an average value per soil class, for example. So in this example, we have the soil map with discrete classes. And we have saturated hydraulic conductivity as a continuous raster. And we can calculate the average value per soil type. Then there are global operations. They consider all the values in a map and the result is, in fact, a non-spatial result, a value. Like, give me the total of all the values in the map or the average. So the value, in this case, is based on all the cells that occur in the map. Example is if we want to calculate the total population, we have a map for each cell, the amount of people living in that area in the pixel, and we simply calculate the total. That's a global operation because all the pixels in the cell contribute to the calculation. The second example is precipitation. If we have a map with the precipitation and we want to calculate the average of the older pixels in the raster, then we use a global operation and the result is the average value of precipitation in the whole raster area. A specific form of map algebra is done with Boolean operations and Boolean operations are done with Boolean maps. Boolean maps are explained in a previous video. They contain values of one for all the pixels that are true and value zero for all the pixels that are considered false. This is typically used for binary maps such as flooded versus non-flooded areas or polluted versus non-polluted. Boolean operators, which I'll explain, result in a Boolean map. The first operator that we can use is and. It's easily demonstrated if we look at the circles here below, where we see that where both circles are present, it results in the area that we consider. A bit more abstract is when we look at the maps. So here we see expression one and we use the and operator with expression two to come to a result map. So if we look at the input expression one, which is true for this pixel and it's false for the pixel in expression two, the result will be zero. However, when both are true, expression one is true and expression two is true, it results also in a true in a result map. When both are false, zero and zero, the result will also be zero. Missing value in expression one or expression two will always result in missing value or no data in the result map. The not operator simply inverts the values. So what was true becomes false and vice versa. So here we see that one becomes zero in the result map and zero in expression one becomes one in the result map. A missing value stays missing value. The or operator can also be demonstrated with the circles. It is true for each circle independently and where they overlap. So if we look at the expression one and expression two map, if expression one has one and expression two has zero, the result will be one. But also if both are one, expression one is one, expression two is one and the result map is also one. And if both are false, expression one and expression two are false, the result map is also false. And missing value stays missing value. If we don't want to have true for where both are true, we use the XOR or exclusive OR operator. Here in the circles, we see that it's only true when they don't overlap. In the maps, we can see it if we evaluate the values. So expression one equals one, expression two equals zero, and that will result in a one in the result map. If expression one and expression two, both are true, are one, it results in zero in the result map. When both are false, zero and zero, it also results in a zero. So only when one of the two is true, it will result in a one if we use the exclusive OR operator. A missing value stays missing value. We have to pay special attention to no data in map algebra. If we use Boolean maps, which have one for true and zero for false, it is different than if we use one for true and no data for false. For some calculations, for example, distance calculations, the distance will be calculated from all no data cells to data cells. And since zero is considered as data, the result will be probably not what you would like to have. So in that case, you need to convert the zeros to no data. So you will calculate distances from no data to all the one pixels. And you have to remember that no data in any of the input maps will always result in no data in the output map.